/*
 *
 * Copyright (c) 2001-2016 泛微软件.
 * 泛微协同商务系统,版权所有.
 *
 */
package weaver.formmode.excel;

import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.ServletException;

import com.api.formmode.cache.CustomSearchComInfo;
import com.api.formmode.cache.ModeFormComInfo;
import com.engine.cube.util.AddSeclevelUtil;
import com.api.cube.util.CubeSearchTransMethod;
import com.engine.common.biz.EncryptConfigBiz;
import com.engine.fnaMulDimensions.util.AccountInfoComInfo;
import com.engine.hrm.entity.HrmBrowserRegionSettingComInfo;
import km.org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.opensaml.xml.security.keyinfo.StaticKeyInfoGenerator;
import weaver.encrypt.EncryptUtil;
import weaver.fna.maintenance.BudgetfeeTypeComInfo;
import weaver.fna.maintenance.FnaSystemSetComInfo;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;

import com.alibaba.fastjson.JSONObject;
import com.api.cube.bean.TabPane;
import com.api.cube.service.CubeSearchService;
import com.api.cube.service.CubeTreeTypeSearch;
import com.api.cube.util.CubeCipherUitl;
import com.cloudstore.dev.api.bean.SplitPageBean;
import com.engine.cube.cmd.app.GetExportSetInfo;
import com.engine.hrm.biz.OrganizationShowSetBiz;
import com.weaver.cssRenderHandler.CssRenderDeal;
import com.weaver.formmodel.util.DateHelper;
import com.weaver.formmodel.util.NumberHelper;
import com.weaver.formmodel.util.StringHelper;

import sun.misc.BASE64Decoder;
import weaver.conn.ConnStatement;
import weaver.conn.RecordSet;
import weaver.crm.Maint.CustomerInfoComInfo;
import weaver.dateformat.DateTransformer;
import weaver.dateformat.TimeZoneVar;
import weaver.docs.docs.DocComInfo;
import weaver.docs.senddoc.DocReceiveUnitComInfo;
import weaver.formmode.BarcodeHandler;
import weaver.formmode.cache.StringCacheMap;
import weaver.formmode.expcard.util.ExpCardUtil;
import weaver.formmode.exttools.impexp.common.FileUtils;
import weaver.formmode.exttools.impexp.db.DatabaseUtils;
import weaver.formmode.interfaces.ExportFieldTransAction;
import weaver.formmode.log.FormmodeLog;
import weaver.formmode.search.FormModeTransMethod;
import weaver.formmode.service.CommonConstant;
import weaver.formmode.tree.CustomTreeUtil;
import weaver.formmode.virtualform.VirtualFormHandler;
import weaver.general.*;
import weaver.hrm.User;
import weaver.hrm.city.CityComInfo;
import weaver.hrm.city.CitytwoComInfo;
import weaver.hrm.country.CountryComInfo;
import weaver.hrm.province.ProvinceComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.workflow.browser.Browser;
import weaver.interfaces.workflow.browser.BrowserBean;
import weaver.proj.Maint.ProjectInfoComInfo;
import weaver.security.util.SecurityMethodUtil;
import weaver.systeminfo.SystemEnv;
import weaver.workflow.field.BrowserComInfo;
import weaver.workflow.request.ResourceConditionManager;
import weaver.workflow.workflow.WorkflowBillComInfo;
import weaver.workflow.workflow.WorkflowRequestComInfo;

/**
 * @version 1.0
 * @author nxh
 */
public class ListExceloutTask implements Runnable {
    private ExcelParaBean epb;
    private String modeCustomid;
    private SplitPageUtil spu = new SplitPageUtil() ;
    private SplitPageParaBean spp = new SplitPageParaBean();
    private BaseBean baseBean=new BaseBean();
    private boolean iscustomstyle=false;//是否自定义样式
    private Map<String, XSSFCellStyle> allstyle = new HashMap<String,XSSFCellStyle>();
    private ArrayList<String> headNameList = new ArrayList<String>();
    private ArrayList<String> columnList = new ArrayList<String>();
    private ArrayList<String> oldcolumnList = new ArrayList<String>();
    private ArrayList<String> trasforMethodList = new ArrayList<String>();
    private ArrayList<String> otherparaList = new ArrayList<String>();
    private List<Integer> colWidthList = new ArrayList<Integer>();
    private Set<Integer> infoindex = new HashSet<Integer>();
    private User user;
    private int defaultWidth=20;
    private Map<String, Object> parmMap;
    private SplitPageBean bean;
    private JSONObject progress = new JSONObject();
    private String key="";
    private int rowindexs = 1;
    private String isexptrees = "";
    private int counts = 0;
    private int expPageSize=1000;//导出数据分页查询,每次5000条
    private String mainTable = "";
    private String detailtable = "";
    /**
     * 脱敏数据是否返回明文
     */
    private boolean isReturnDecryptData = false;
    public ListExceloutTask(Map<String, Object> parmMap,SplitPageBean bean,User user){
        this.parmMap=parmMap;
        this.bean=bean;
        this.user=user;
        //标识该次导出的唯一标识
        this.key=Util.null2String(parmMap.get("key"));
        this.isReturnDecryptData = (Boolean) parmMap.get("isReturnDecryptData");
    }
    /**
     * 主表导出记录数
     */
    private int maincount=0;



    @Override
    public void run() {
        try {
            ExpExcelUtil.refreshExpUserStateNew(user.getUID());
            this.doExp();
        } catch (Exception e) {
            new BaseBean().writeLog(e);
        }finally {
            ExpExcelUtil.removeExpUserState(user.getUID());
        }
    }

    /**
     * 通过区id获取全路径
     * @param areaId
     * @return
     */
    private String getProvinceNameAndAreaBy(String areaId) {
        //区县
        CitytwoComInfo citytwoComInfo = new CitytwoComInfo();
        //城市
        CityComInfo cityComInfo = new CityComInfo();
        //省份
        ProvinceComInfo provinceComInfo = new ProvinceComInfo();
        //国家
        CountryComInfo countryComInfo = new CountryComInfo();

        //区id
        String citypid = citytwoComInfo.getCitypid(areaId);
        //区名
        String areaName = citytwoComInfo.getCityname(areaId);

        //城市id
        String cityprovinceid = cityComInfo.getCityprovinceid(citypid);
        //城市name
        String cityname = cityComInfo.getCityname(citypid);

        //省id
        String provincecountryid = provinceComInfo.getProvincecountryid(cityprovinceid);
        //省name
        String provincename = provinceComInfo.getProvincename(cityprovinceid);

        return buildCountryProvinceCity(provincename, cityname, areaName);
    }

    private String buildCountryProvinceCity(String provinceName, String cityName, String areaName) {
        String pathDelimiter = new HrmBrowserRegionSettingComInfo().getPathDelimiter("1");
        StringJoiner stringJoiner = new StringJoiner("-");
        if(!StringUtil.isEmpty(pathDelimiter)){
            stringJoiner = new StringJoiner(pathDelimiter);
        }
        if (!StringUtil.isEmpty(provinceName)) {
            stringJoiner.add(provinceName);
        }
        if (!StringUtil.isEmpty(cityName)) {
            stringJoiner.add(cityName);
        }
        if (!StringUtil.isEmpty(areaName)) {
            stringJoiner.add(areaName);
        }
        return stringJoiner.toString();
    }


    private void doExp() throws Exception{
        //第一步,准备导出
        progress.put("step", "start");
        syncProgress();
        String showOrder = Util.null2String(parmMap.get("showOrder"));
        String iscustomsearch = Util.null2String(parmMap.get("iscustomsearch"));
        String from = Util.null2String(parmMap.get("from"));
        modeCustomid = Util.null2String(parmMap.get("modeCustomid"));
        String excelName = Util.null2String(parmMap.get("excelName"));
        String isexptree = Util.null2String(parmMap.get("isexptree"));
        this.isexptrees = isexptree;
        String isSelectGroup = Util.null2String(parmMap.get("isSelectGroup"));
        RecordSet rs = new RecordSet();
        boolean isCustomExportField =false;//是否自定义导出字段
        int isexportfield = 0;//
        boolean isgroupexport=false;//是否分组导出
        String sql="select isexportfield,isgroupexport,iscustomstyle from mode_exportexcelset where customid=?";
        rs.executeQuery(sql, modeCustomid);
        if (rs.next()) {
            isCustomExportField="1".equals(rs.getString("isexportfield"));
            isexportfield =Util.getIntValue(rs.getString("isexportfield"),0);
            isgroupexport="1".equals(rs.getString("isgroupexport"));
            iscustomstyle="1".equals(rs.getString("iscustomstyle"));
        }
        //查询用户是否设置了列定制显示
        boolean iscolumnMake = false;
        String  sqlQueryColMake = " select count(dataindex) count from cloudstore_defcol where PAGEUID='mode_customsearch:"+modeCustomid+"' and  display='0' and dataindex !='isshowlist' and userid = "+user.getUID();
        RecordSet rsQueryColMake = new RecordSet();
        int queryColMake = 0;
        rsQueryColMake.execute(sqlQueryColMake);
        if(rsQueryColMake.next()){
            queryColMake = Util.getIntValue(rsQueryColMake.getString("count"),0);
            if(queryColMake>=1){
                iscolumnMake=true;
            }
        }

        if("1".equals(isexptree) || !iscolumnMake){
            isexportfield = 0;
        }
        String tablesql ="select formid,detailtable from  mode_customsearch where id=?";
        rs.executeQuery(tablesql, modeCustomid);
        if(rs.next()){
            WorkflowBillComInfo workflowBillComInfo = new WorkflowBillComInfo();
            int formid = rs.getInt("formid");
            detailtable = rs.getString("detailtable");
            mainTable = workflowBillComInfo.getTablename(String.valueOf(formid));
            if(VirtualFormHandler.isVirtualForm(formid)){
                mainTable = VirtualFormHandler.getRealFromName(mainTable);
                ModeFormComInfo modeFormComInfo = new ModeFormComInfo();
                String vformtype = modeFormComInfo.getVformtype(formid);
                String vsql = modeFormComInfo.getVsql(formid);
                if("2".equals(vformtype)){
                    mainTable="("+vsql+") cube_vsql";
                }
            }
        }
        boolean haveMergeLine = false;
        sql = "select linemergel from mode_customsearch where id=?";
        rs.executeQuery(sql, modeCustomid);
        if(rs.next()){
            String linemerge = Util.null2String(rs.getString("linemergel"));
            if(linemerge.equals("1")){
                rs.executeQuery("select 1 from mode_searchLineMergel a left join mode_customdspfield b on a.fieldid=b.fieldid where a.fieldid>0 and b.isshow=1 and b.customid=? and a.customid=?", modeCustomid,modeCustomid);
                if(rs.next()){
                    haveMergeLine = true;
                }
            }
        }
        if (bean==null) {
            return;
        }
        try {
            String pageUId = StringHelper.null2String(bean.getRootMap().getString("pageUid"));
            if(StringHelper.isEmpty(modeCustomid)&&!StringHelper.isEmpty(pageUId)){
                modeCustomid = pageUId.replace("mode_customsearch:", "");
            }
            //重新初始化epb
            epb = new ExcelParaBean();
            String copyWhere = "";
            JSONObject json = bean.getSql();
            String backfields = StringHelper.null2String(json.get("backfields"));
            String sqlorderby = StringHelper.null2String(json.get("sqlorderby"));
            String sqlprimarykey = StringHelper.null2String(json.get("sqlprimarykey"));
            String sqlwhere = StringHelper.null2String(json.get("sqlwhere"));
            if(isgroupexport&&"true".equals(isSelectGroup)){
                //当点击分组，去除最后一个分组带来的sql过滤。
                String[] sqlSplit = sqlwhere.split("and");
                String sqlFlag =sqlSplit[sqlSplit.length-1];
                if(!sqlFlag.toLowerCase().trim().equals("t1.id = t2.sourceid") && sqlFlag.indexOf("(") < 0 && sqlFlag.toLowerCase().trim().indexOf("d1.")<0){
                    for(int i = 0; i < sqlSplit.length-1;i++){
                        String sqlWhere  = sqlSplit[i];
                        copyWhere += sqlWhere + " and ";
                    }
                    if(!copyWhere.equals("")){
                        sqlwhere = copyWhere.substring(0,copyWhere.length()-4);
                    }
                }
            }
            String sqlform = StringHelper.null2String(json.get("sqlform"));

            String sum = StringHelper.null2String(json.getString("sumColumns"));

            String poolname = "";
            if(json.containsKey("poolname")){
                poolname = StringHelper.null2String(json.get("poolname"));
            }
            Map tempMap = new HashMap();
            if(isexportfield==0 || isexportfield == 1){
                tempMap = getExportFieldsHead(modeCustomid,user,isCustomExportField);
            }else{
                tempMap = getExportFieldsHeadByUser(modeCustomid,user,isCustomExportField);
            }

            List<Map<String,String>> resultList = (List<Map<String, String>>) tempMap.get("resultList");
            ArrayList headParaList = new ArrayList();
            for (int i = 0; i < resultList.size(); i++) {
                Map<String,String> mapTemp  = resultList.get(i);
                String[] headParas = new String[5];
                headParas[0] = mapTemp.get("text");
                headParas[1] = mapTemp.get("column").toLowerCase();
                headParas[2] = mapTemp.get("transmethod");
                headParas[3] = mapTemp.get("otherpara");
                headParas[4] = mapTemp.get("id");
                headParaList.add(headParas);
            }
            if(sqlprimarykey.equals("t1.id,d_id")){
                sqlprimarykey = "t1.id";
            }

            epb.setHeadParaList(headParaList);
            epb.setPageIndex(1);
            epb.setPageSize(10);
            epb.setDataSource("");
            epb.setPoolname(poolname);
            epb.setParams("");
            epb.setCountColumns(sum);
            epb.setPageBySelf("");
            epb.setBackFields(backfields);
            epb.setDistinct(false);
            epb.setPrimaryKey(sqlprimarykey);
            epb.setSqlFrom(sqlform);
            epb.setSqlWhere(sqlwhere);
            epb.setSqlOrderBy(sqlorderby);
            epb.setSqlGroupBy("");
            epb.setSortWay(1);

            /*结束位置*/
            /*修改导出Excel名称*/
            rs.writeLog("excelName   lanqq放入epb.setExcelFileName(excelName)是否乱码---236:"+excelName);
            epb.setExcelFileName(excelName);
        } catch (Exception e) {
            throw new ServletException(SystemEnv.getHtmlLabelName(503398,user.getLanguage()));//初始化ExcelParaBean出现错误
        }
        if (epb == null){
            throw new ServletException("ExcelParaBeanForServlet Bean does not exist in session");//ExcelParaBeanForServlet Bean没有在seesion在存在
        }
        ArrayList headParaList = epb.getHeadParaList();//7
        int pageIndex = epb.getPageIndex();//1
        int pageSize = epb.getPageSize();//10
        String dataSource = epb.getDataSource();//""
        String poolname = epb.getPoolname();//""
        String params = epb.getParams();//""
        String countColumns = epb.getCountColumns();//""
        String pageBySelf = epb.getPageBySelf();//""
        Map<String,Integer>	countColumnsDbType = this.getCountColumnsDbType(countColumns,epb.getSqlFrom());
        String backfields = "";
        String temp_backfields = "";//用于获取相关统计数据。
        if(isexportfield==0 || isexportfield == 1){
            backfields = getExportFieldsHead(modeCustomid,isCustomExportField);
        }else{
            backfields = getExportFieldsHead2(modeCustomid,user,isCustomExportField);
            temp_backfields = getExportFieldsHead(modeCustomid,isCustomExportField);
        }

        if(isexportfield== 2){
            spp.setBackFields(temp_backfields);
        }else{

            spp.setBackFields(backfields);// t1.id,t1.formmodeid
        }
        spp.setDistinct(epb.getIsDistinct());//false
        spp.setPrimaryKey(epb.getPrimaryKey());//t1.id
        spp.setSqlFrom(epb.getSqlFrom());//
        spp.setSqlWhere(epb.getSqlWhere());// where t1.formmodeid = 686  and t1.id = t2.sourceid
        String ids = Util.null2String(parmMap.get("ids"));//选中的id
        BASE64Decoder decoder = new BASE64Decoder();
        ids = new String(decoder.decodeBuffer(ids),"UTF-8");
        if(ids.length()>0){//勾选导出
            ids=SecurityMethodUtil.checkSql(ids);
            ids = ids.replaceAll(",", "','");
            String sqlwhere = epb.getSqlWhere()+" and "+epb.getPrimaryKey()+" in ('"+ids+"')";
            spp.setSqlWhere(sqlwhere);
        }
        spp.setSqlOrderBy(epb.getSqlOrderBy());//t1.id desc
        spp.setSqlGroupBy(epb.getSqlGroupBy());//""
        spp.setCountColumns(countColumns);	//统计项
        spp.setSortWay(epb.getSortWay());//1
        spp.setPoolname(epb.getPoolname());//""
        spp.setCountColumnsDbType(countColumnsDbType);
        spu.setSpp(spp);
        Map<String,String> columnMap = new HashMap<>();
        Map<String,String> headNameMap = new HashMap<>();
        Map<String,String> trasforMethodMap = new HashMap<>();
        Map<String,String> otherparaMap = new HashMap<>();
        for (int i = 0; i < headParaList.size(); i++) {
            String headName = ((String[]) headParaList.get(i))[0];
            if(headName.indexOf("~`~`7")!=-1){
                headName = Util.formatMultiLang(headName,user.getLanguage()+"");
            }
            headName=Util.toExcelData(headName);
            String headParaName = ((String[]) headParaList.get(i))[1];
            if(!"idskey_forused".equals(headName)){
                String[] temp = (String[]) headParaList.get(i);
                if(!isCustomExportField){//不是自定义导出字段
                    columnList.add(headParaName);
                    headNameList.add(headName);
                    trasforMethodList.add(temp[2]);
                    otherparaList.add(temp[3]);
                }else{
                    columnMap.put(temp[4],headParaName);
                    headNameMap.put(temp[4],headName);
                    trasforMethodMap.put(temp[4],temp[2]);
                    otherparaMap.put(temp[4],temp[3]);
                }
            }
        }
        if(isCustomExportField){//自定义导出字段:按照导出字段设置进行排序
            List<String> list = getExportOrder(modeCustomid,user);
            Map<String,Integer> colWidth = getColWidth(modeCustomid);
            for(int i=0;i<list.size();i++){
                String fieldid = list.get(i);
                columnList.add(columnMap.get(fieldid));
                headNameList.add(headNameMap.get(fieldid));
                trasforMethodList.add(trasforMethodMap.get(fieldid));
                otherparaList.add(otherparaMap.get(fieldid));
                if(colWidth.containsKey(fieldid)){
                    colWidthList.add(colWidth.get(fieldid));
                }else{
                    colWidthList.add(defaultWidth);
                }
            }
        }
        SXSSFWorkbook wb = new SXSSFWorkbook();
        //导出样式定义
        initStyle(wb);
        String primaryKeyFieldName = epb.getPrimaryKey();
        if(primaryKeyFieldName.contains(".")){
            primaryKeyFieldName = primaryKeyFieldName.substring(primaryKeyFieldName.indexOf(".")+1);
        }
        //分组导出
        Map<String,String> sheets = getSheets(modeCustomid,epb.getExcelFileName(),user);
        //第二步,导出sheet
        progress.put("step", "expSheet");
        progress.put("sheetcount", sheets.size());
        String sqlWhere = spp.getSqlWhere();
        int sheetindex=1;
        this.oldcolumnList = this.columnList;
        for(Map.Entry<String,String> entry: sheets.entrySet()){
            if (StringCacheMap.containsKey(key+"_cancel")) {//如果取消
                break;
            }
            ExpExcelUtil.refreshExpUserStateNew(user.getUID());
            progress.put("currsheet", sheetindex);
            sheetindex++;
            String value = entry.getValue();
            SXSSFSheet sheet;
            try {
                sheet = wb.createSheet(value);
            } catch (Exception e) {
                value=value+System.currentTimeMillis();
                sheet = wb.createSheet(value);
            }
            //sheet.createFreezePane( 0, 1, 0, 1 );
            String key = entry.getKey();
            String sqlWhere2 = getExportSqlWhere(modeCustomid,key,sqlWhere);
            spp.setSqlWhere(sqlWhere2);
            Map<String, String> decimalCV = this.getDecimalCV(countColumns,epb.getSqlFrom());
            Map<String,String> countCV = this.getCountCV(countColumns);
            if(isexportfield== 2){
                spp.setBackFields(backfields);
            }
            int total=0;
            sql = this.getData(user, dataSource, poolname, pageIndex, pageSize, showOrder,true);//查询总记录数
            ConnStatement cs=null;
            try {
                cs = new ConnStatement();
                if((poolname.equals("")||poolname.equalsIgnoreCase("null"))){//实际表单
                    cs.setStatementSql(sql) ;
                }else {
                    cs.setStatementSql(sql,poolname) ;
                }
                cs.executeQuery() ;
                if (cs.next()) {
                    total=Util.getIntValue(cs.getString(1), 0);
                }
            } catch (Exception e) {
                new BaseBean().writeLog(e);
            }finally {
                if (cs!=null) {
                    try {
                        if((poolname.equals("")||poolname.equalsIgnoreCase("null"))){//实际表单
                            cs.close();
                        }else {
                            cs.close(poolname);
                        }
                    } catch (Exception e) {
                        new BaseBean().writeLog(e);
                    }
                }
            }
            if (sheetindex==2) {
                this.maincount=total;
            }
            progress.put("total", total);
            progress.put("current", 1);
            syncProgress();
            //统计字段是否第一列
            boolean flag = false;
            String[] countColumnArr = countColumns.toLowerCase().split(",");
            if(columnList.size()>0&&countColumnArr[0].equals((String) columnList.get(0))){
                flag = true;
            }
            int rownum = 1;
            int dj_row = 1;//冻结行
            if(haveMergeLine && !"1".equals(isexptree) && !isCustomExportField){
                //合并列信息
                Map<String, Object> mergeMap = mergelinef(modeCustomid,flag);
                ArrayList<String[]> heads = (ArrayList<String[]>) mergeMap.get("heads");
                ArrayList<String> mergeHeads = (ArrayList<String>) mergeMap.get("mergeHeads");
                XSSFCellStyle headStyle = allstyle.get("headerStyle");
                headStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                if(heads.size()>0){
                    dj_row = heads.size();
                }
                for(int i=0;i<heads.size();i++){
                    SXSSFRow row = sheet.createRow(i);
                    for(int j=0;j<heads.get(i).length;j++){
                        SXSSFCell cell = row.createCell(j);
                        String cellvalue = Util.null2String(heads.get(i)[j]);
                        if(i == heads.size()-1){
                            int fieldindex = getFieldIndex(Util.null2String(heads.get(i)[j]), oldcolumnList);
                            if(fieldindex>-1){
                                cellvalue = headNameList.get(fieldindex);
                            }
                        }
                        cell.setCellValue(cellvalue);
                        cell.setCellStyle(headStyle);
                    }
                }
                ArrayList<String> tempColumnList = new ArrayList<String>();
                ArrayList<String> temptrasforMethodList = new ArrayList<String>();
                ArrayList<String> tempotherparaList = new ArrayList<String>();
                String [] lastHeadRow = heads.get(heads.size()-1);
                for(int i=0;i<lastHeadRow.length;i++){
                    if(flag && i == 0){
                        continue;
                    }
                    tempColumnList.add(lastHeadRow[i]);
                    int fieldindex = getFieldIndex(Util.null2String(lastHeadRow[i]), columnList);
                    if(fieldindex>-1){
                        temptrasforMethodList.add(trasforMethodList.get(fieldindex));
                        tempotherparaList.add(otherparaList.get(fieldindex));
                    }else{
                        temptrasforMethodList.add("");
                        tempotherparaList.add("");
                    }

                }
                this.columnList = tempColumnList;
                this.trasforMethodList = temptrasforMethodList;
                this.otherparaList = tempotherparaList;
                for(String mergeHead : mergeHeads){
                    String[] mergelines = mergeHead.split(",");
                    if(mergelines.length<4){
                        continue;
                    }else{
                        int startrow = Util.getIntValue(mergelines[0]);
                        int overrow = Util.getIntValue(mergelines[1]);
                        int startline = Util.getIntValue(mergelines[2]);
                        int overline = Util.getIntValue(mergelines[3]);
                        if(startrow==overrow && startline==overline){
                            continue;
                        }else{
                            sheet.addMergedRegion(new CellRangeAddress(startrow, overrow, startline, overline));
                        }
                    }
                }
                rownum = heads.size();
            }else{
                SXSSFRow row = sheet.createRow(0);
                XSSFCellStyle headStyle = allstyle.get("headerStyle");
                SXSSFCell cell;
                if(flag){
                    cell = row.createCell(0);
                    cell.setCellValue("Header");
                    cell.setCellStyle(headStyle);
                }
                for (int i = 0; i < headNameList.size(); i++) {
                    cell=row.createCell(flag?(i+1):i);
                    cell.setCellValue(Util.null2String(headNameList.get(i)));
                    cell.setCellStyle(headStyle);
                    if(isCustomExportField){
                        sheet.setColumnWidth(i, colWidthList.get(i)*256);
                    }else {
                        sheet.setColumnWidth(i, defaultWidth*256);
                    }
                }
            }
            sheet.createFreezePane( 0, dj_row, 0, dj_row );
            if("1".equals(isexptree)){
                CubeTreeTypeSearch cubeTreeTypeSearch = new CubeTreeTypeSearch();
                Map treeMap = new HashMap<>();
                List cu = new ArrayList<>();
                treeMap = cubeTreeTypeSearch.treeType(backfields,epb.getSqlFrom(),epb.getSqlWhere(),epb.getSqlOrderBy(),modeCustomid,cu,pageIndex,1000,"",user, true,ids);
                ArrayList allDatas = (ArrayList)treeMap.get("treedatas");
                ArrayList countDatas = allDatas;
                writeTreeRowData(allDatas, countColumns, countColumnsDbType, wb, sheet, flag, from, iscustomsearch, countColumnArr, countCV, decimalCV); //写入树形数据。
                this.rowindexs = 1;
                estimateData(countDatas,sheet);    //处理层级显示。
            }else{
                int totalPage=1;
                totalPage=(total-1)/this.expPageSize+1;
                for (int i = 1; i <=totalPage; i++) {
                    sql = this.getData(user, dataSource, poolname, i, this.expPageSize, "",false);
                    writeRowData(sql,poolname, countColumns, countColumnsDbType, wb, sheet, flag, from, iscustomsearch, countColumnArr, countCV, decimalCV,rownum);
                    rownum+=this.expPageSize;
                }
            }
            progress.put("current", total);
            syncProgress();
        }
        if (StringCacheMap.containsKey(key+"_cancel")) {//如果取消
            StringCacheMap.remove(key+"_cancel");
            StringCacheMap.remove(key);
            return;
        }
//        String filename=epb.getExcelFileName()+".xlsx";
        //第三步,创建文件
        progress.put("step", "createFile");
        syncProgress();
        this.createFile(wb, key);
        //第四步,导出完成
        progress.put("step", "end");
        progress.put("filename", "");
        syncProgress();
    }

    private String getExportFieldsHead2(String customId, User user, boolean isCustomExportField) {
        String backfields = null;

        CustomSearchComInfo customSearchComInfo = new CustomSearchComInfo();
        String modeId = customSearchComInfo.getModeId(customId);
        int formId = com.api.formmode.page.util.Util.toInt(customSearchComInfo.getFormId(customId), 0);
        String detailTable = customSearchComInfo.getDetailTable(customId);
        // if(isCustomExportField){//自定义导出字段
        StringBuffer fields = new StringBuffer();
        fields.append(epb.getPrimaryKey());
        RecordSet recordSet = new RecordSet();//得到所有的字段
        //String sql = "select wbf.fieldname,wbf.viewtype from mode_exportexcelfield me,workflow_billfield wbf where me.fieldid=wbf.id and me.customid="+customId;

        String sql = "  select dataindex from cloudstore_defcol where PAGEUID='mode_customsearch:" + customId + "' and  display='0' and userid = "+user.getUID()+" order by orders";
        recordSet.execute(sql);
        while(recordSet.next()){
            String fieldname = recordSet.getString("dataindex");
            if( fieldname.toLowerCase().startsWith("isshowlist") ){
                continue;
            }
            if( fieldname.toLowerCase().startsWith("d_") ){//明细表字段
                DatabaseUtils databaseUtils = new DatabaseUtils();
                String fieldnametemp = fieldname.substring(2, fieldname.length());
                if(databaseUtils.existsColumn(detailTable,fieldnametemp)){
                    fields.append(",d1."+fieldnametemp+" as d_"+fieldnametemp);
                }else{
                    if(("t1."+fieldname).equalsIgnoreCase(epb.getPrimaryKey()))continue;
                    fields.append(",t1."+fieldname);
                }
            }else{//主表字段
                if(("t1."+fieldname).equalsIgnoreCase(epb.getPrimaryKey()))continue;
                fields.append(",t1."+fieldname);
            }

        }

        backfields = fields.toString();

        return backfields;

    }

    public Map<String, Object> mergelinef(String modeCustomid,boolean flag){
        Map<String, Object> mergeMap = new HashMap<String, Object>();
        CubeSearchService cubeSearchService = new CubeSearchService();
        cubeSearchService.setUser(user);
        List<Map<String, Object>> mergeInfos = cubeSearchService.getLineMergeInfos(modeCustomid,2);
        //获取所有合并列中最大的层级
        int maxTier = getMaxTier(mergeInfos);
        ArrayList<String> columnList1 = new ArrayList<String>();
        ArrayList<String> headNameList1 = new ArrayList<String>();
        if(flag){//如果第一列是合并列
            columnList1.add("Header");
            headNameList1.add("Header");
            for(String column : oldcolumnList){
                columnList1.add(column);
            }
            for(String headName : headNameList){
                headNameList1.add(headName);
            }
        }else{
            columnList1 = oldcolumnList;
            headNameList1 = headNameList;
        }
        ArrayList<String[]> heads = new ArrayList<String[]>();
        for(int i=0;i<maxTier;i++){
            heads.add(new String[columnList1.size()]);
        }
        ArrayList<String> mergeHeads =new ArrayList<String>();
        ArrayList<String> treatedColumn =new ArrayList<String>();
        int linenum = 0;
        for(int j = 0;j<columnList1.size();j++){
            boolean treatedColumnFlag = isContainsString(columnList1.get(j),treatedColumn);
            if(treatedColumnFlag){
                continue;
            }
            //字段所在合并列的下标
            int index = isMergeField(columnList1.get(j),mergeInfos);
            if(index<0){//index小于0说明该字段没有被合并
                for(int i =0;i<maxTier;i++){
                    if(i == maxTier-1){
                        heads.get(i)[linenum] = columnList1.get(j);
                    }else{
                        heads.get(i)[linenum] = headNameList1.get(j);
                    }
                }
                int overrow = maxTier-1;
                String mergeHead = "0,"+overrow+","+linenum+","+linenum;
                mergeHeads.add(mergeHead);
                linenum++;
            }else{
                Map<String, Object> mergeInfo = mergeInfos.get(index);
                String mergeName = Util.null2String(mergeInfo.get("mergename"));
                int tempTier = Util.getIntValue(Util.null2String(mergeInfo.get("maxTier")), 0);
                int fieldcount = Util.getIntValue(Util.null2String(mergeInfo.get("fieldcount")), 0);
                int overrow = 1;
                int mergerows = 1;
//				if(tempTier < maxTier){
//					mergerows = maxTier/tempTier;
//					if(maxTier%tempTier>0){
//						overrow = mergerows+1;
//					}else{
//						overrow = mergerows;
//					}
//					overrow = mergerows;
//				}
                for(int i=0;i<fieldcount;i++){
                    for(int row=0;row<overrow;row++){
                        heads.get(row)[linenum+i] = mergeName;
                    }
                }
                int tempoverrow = overrow-1;
                int overline = linenum+fieldcount-1;
                String mergeHead = "0,"+tempoverrow+","+linenum+","+overline;
                mergeHeads.add(mergeHead);
                List<Map<String, Object>> childrens = (List<Map<String, Object>>) mergeInfo.get("children");
                childMergeLines(childrens, heads, mergeHeads, overrow, linenum, mergerows, treatedColumn,maxTier,columnList1,headNameList1);
                linenum = linenum + fieldcount;
            }
        }
        mergeMap.put("heads", heads);
        mergeMap.put("mergeHeads", mergeHeads);
        return mergeMap;
    }
    public void childMergeLines(List<Map<String, Object>> childrens,ArrayList<String[]> heads,ArrayList<String> mergeHeads,int startrow,int startline,int mergerows,ArrayList<String> treatedColumn,int maxTier
            ,ArrayList<String> columnList1,ArrayList<String> headNameList1) {
        for(Map<String, Object> children : childrens){
            String childrenMergeName = Util.null2String(children.get("mergename"));
            String fieldname = Util.null2String(children.get("fieldname"));
            int fieldcount = Util.getIntValue(Util.null2String(children.get("fieldcount")), 1);
            int fieldTier = Util.getIntValue(Util.null2String(children.get("fieldTier")), 1);
            List<Map<String, Object>> childrens1= (List<Map<String, Object>>) children.get("children");
            if(fieldname.equals("")){
                for(int i =0;i<fieldcount;i++){
                    for(int j =0;j<mergerows;j++){
                        heads.get(startrow+j)[startline+i] = childrenMergeName;
                    }
                }
                int overrow = startrow+mergerows-1;
                int overline = startline+fieldcount-1;
                String mergeHead = startrow+","+overrow+","+startline+","+overline;
                mergeHeads.add(mergeHead);
                childMergeLines(childrens1, heads, mergeHeads, overrow+1, startline, mergerows, treatedColumn,maxTier,columnList1,headNameList1);
                startline = startline+fieldcount;
            }else{
                int temprows = maxTier-startrow;
                for(int i = 0; i<temprows;i++){
                    int fieldindex = getFieldIndex(fieldname,columnList1);
                    if(fieldindex>-1){
                        if(startrow+i == maxTier-1){
                            heads.get(startrow+i)[startline] = fieldname;
                        }else{
                            heads.get(startrow+i)[startline] = headNameList1.get(fieldindex);
                        }
                    }else{
                        heads.get(startrow+i)[startline] = "";
                    }
                }
                int overrow = startrow+temprows-1;
                String mergeHead = startrow+","+overrow+","+startline+","+startline;
                mergeHeads.add(mergeHead);
                treatedColumn.add(fieldname);
                startline = startline+1;
            }
        }

    }
    public int getFieldIndex(String fieldname,ArrayList<String> columnList1) {
        int index = -1;
        for(int i=0;i<columnList1.size();i++){
            if(fieldname.equalsIgnoreCase(columnList1.get(i))){
                index = i;
                break;
            }
        }
        return index;

    }
    public int getMaxTier(List<Map<String, Object>> mergeInfos) {
        int maxTier = 0;
        for(Map<String, Object> mergeInfo : mergeInfos){
            int tempTier = Util.getIntValue(Util.null2String(mergeInfo.get("maxTier")), 0);
            if(tempTier>maxTier){
                maxTier = tempTier;
            }
        }
        return maxTier;
    }

    public int isMergeField(String fieldname,List<Map<String, Object>> mergeInfos){
        int index = -1;
        boolean flag = false;
        for(int i=0;i<mergeInfos.size();i++){
            List<String> fields = (List<String>) mergeInfos.get(i).get("fields");
            //将mergeinfos获取的fields转小写，再匹配fieldname
            flag = isContainsString(fieldname,fields);
            if(flag) {
                index = i;
                break;
            }
        }
        return index;
    }

    public boolean isContainsString(String fieldname,List<String> list) {
        boolean flag = false;
        for(int j=0;j<list.size();j++) {
            String name = list.get(j).toLowerCase();
            if(fieldname.equals(name)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    /**
     * 按行写入数据
     */
    private void writeRowData(String sql,String poolname,String countColumns,Map<String,Integer>	countColumnsDbType,SXSSFWorkbook workbook,
                              SXSSFSheet sheet,boolean flag,String from,String iscustomsearch,String[] countColumnArr,Map<String,String> countCV
            ,Map<String,String> decimalCV,int rownum){
        Map<String,String> qfwsMap0 = new ConcurrentHashMap<String,String>();
        Map<String,String> qfwsMap1 = new ConcurrentHashMap<String,String>();
        Map<String,String> selectMap = new ConcurrentHashMap<String,String>();
        HashMap<String,HashMap<String, String>> browserMap = new HashMap<String, HashMap<String,String>>();
        Map<String,Map<String,String>> barcodeMap=new HashMap<String,Map<String,String>>();
        String timeZone = TimeZoneVar.getTimeZone();
        String starttime = DateHelper.getCurDateTime();
        long begin = new Date().getTime();
        RecordSet RecordSet = new RecordSet();
        RecordSet rs = new RecordSet();
        BrowserComInfo BrowserComInfo  = null;
        ProjectInfoComInfo ProjectInfoComInfo1 = null;
        ResourceComInfo rc  = null;
        CustomerInfoComInfo cci  = null;
        WorkflowRequestComInfo WorkflowRequestComInfo1  = null;
        ResourceConditionManager rcm  = null;
        DocReceiveUnitComInfo duc  = null;
        DocComInfo DocComInfo1  = null;
        ExportFieldTransAction fieldTransAction = null;
        //导出转换接口字段配置
        List<String> transFields = new ArrayList<String>();
        Map<String, Object> transMap = new HashMap<String, Object>();
        String tsql="select exptranspath from mode_exportexcelset where customid=?";
        rs.executeQuery(tsql, modeCustomid);
        String exptranspath="";
        if (rs.next()) {
            exptranspath=Util.null2String(rs.getString("exptranspath"));
        }
        if (!"".equals(exptranspath)) {
            try {
                exptranspath=exptranspath.replaceAll(".java$", "").replaceAll(".class$", "");
                Object interfaceObject = Class.forName(exptranspath).newInstance();
                if (interfaceObject instanceof ExportFieldTransAction) {
                    fieldTransAction=(ExportFieldTransAction) interfaceObject;
                }
            } catch (Exception e) {
                baseBean.writeLog(e);
            }
            tsql = "select fieldid from mode_expfieldtrans where customid=?";
            rs.executeQuery(tsql, modeCustomid);
            while (rs.next()) {
                String fieldid = Util.null2String(rs.getString("fieldid"));
                transFields.add(fieldid);
            }
            //导出转换接口参数
            transMap.put("customid", modeCustomid);
            if (transFields.size()>0) {
                tsql = "select modeid,formid from mode_customsearch where id=?";
                rs.executeQuery(tsql, modeCustomid);
                if (rs.next()) {
                    String modeid = Util.null2String(rs.getString("modeid"));
                    String formid = Util.null2String(rs.getString("formid"));
                    transMap.put("modeid", modeid);
                    transMap.put("formid", formid);
                }
            }
        }
        try {
            BrowserComInfo = new BrowserComInfo();
            ProjectInfoComInfo1 = new ProjectInfoComInfo();
            rc = new ResourceComInfo();
            cci = new CustomerInfoComInfo();
            WorkflowRequestComInfo1 = new WorkflowRequestComInfo();
            rcm = new ResourceConditionManager();
            duc = new DocReceiveUnitComInfo();
            DocComInfo1 = new DocComInfo();
        } catch (Exception e1) {
            baseBean.writeLog(e1);
        }
        FormModeTransMethod formModeTransMethod = new FormModeTransMethod();
        RecordSet rs_encrypt = new RecordSet();
        try {
            if(isReturnDecryptData)rs_encrypt.isReturnDecryptData(true);
            if((poolname.equals("")||poolname.equalsIgnoreCase("null"))){//实际表单
                //TODO xzl 密级
                rs_encrypt.executeQuery(sql.replaceAll(",t1.seclevel ",""));
            }else {
                rs_encrypt.executeQueryWithDatasource(sql,poolname);
            }
            int rowindex=rownum;
            XSSFCellStyle doubleStyle = allstyle.get("doubleStyle");
            XSSFCellStyle singleStyle = allstyle.get("singleStyle");
            int random =(int) (20+Math.random()*30)+rowindex;
            int multiple=1;
            boolean havedata=false;
            while (rs_encrypt.next()) {
                havedata=true;
                if (random==rowindex) {
                    if (StringCacheMap.containsKey(key+"_cancel")) {//如果取消
                        break;
                    }
                    progress.put("current", rowindex);
                    syncProgress();
                    random =(int) (20+Math.random()*30)+random;
                }
                if (rowindex==multiple*1000) {//每1w条数据刷新下当前用户导出状态,防止数据过多超过60s未活动被移除
                    ExpExcelUtil.refreshExpUserStateNew(user.getUID());
                    multiple++;
                }
                Map<String, String> data   = recordSet2Map(rs_encrypt);
                boolean barFlag = true;
                transMap.put("data", data);
                SXSSFRow row = sheet.createRow(rowindex);
                XSSFCellStyle cellStyle = rowindex%2==0?doubleStyle:singleStyle;
                //如果第一列有统计字段,则空一列
                SXSSFCell cell;
                if(flag){
                    cell=row.createCell(0);
                    cell.setCellValue("");
                    cell.setCellStyle(cellStyle);
                }
                //查询是否开启了条形码功能
                String isUsed = "";
                String codenum = "";
                for (int i = 0; i < columnList.size(); i++) {
//	            	XSSFCellStyle cellStyle1 = (XSSFCellStyle) workbook.createCellStyle();
//	            	cellStyle1 = getCellStyle(cellStyle1,rowindex);
                    //cellStyle1 = rowindex%2==0?doubleStyle:singleStyle;
                    String tempColumnName = Util.null2String(columnList.get(i)).toLowerCase();
                    if(tempColumnName.equals("")){
                        cell=row.createCell(flag?(i+1):i);
                        cell.setCellStyle(cellStyle);
                        cell.setCellValue("");
                        continue;
                    }
                    String tempTransfMethod = (String) trasforMethodList.get(i);
                    String otherpara = getRealOtherPara((String) otherparaList.get(i),data);
                    String val =  StringHelper.null2String(data.get(tempColumnName));
                    transMap.put("columnname", tempColumnName);
                    transMap.put("value", val);
                    String modeid = "";
                    String billid = "";
                    String formid = "";
                    String customid = "";
                    String fieldid = "";
                    barFlag = true;

                    if("prj_viewprocess".equalsIgnoreCase(from)&&"finish".equalsIgnoreCase(tempColumnName)){//项目任务列表
                        tempTransfMethod="";
                    }
                    String transvalue = "";
                    String fieldhtmltype = "";
                    String fieldtype = "";
                    int numbertype = 0;
                    if (otherpara==null){
                        try {
                            transvalue = Util.useSpecialTreat(tempTransfMethod, Util.null2String(data.get(tempColumnName)));
                        } catch (Exception e) {
                            baseBean.writeLog(e);
                        }
                    } else {
                        String[] tempStr = Util.TokenizerString2(otherpara, "+");
                        otherpara = otherpara+"+isExcelOut";
                        if(tempStr.length<9){//创建人,创建日期,标签等特殊字段
                            try {
                                if ("modedatacreatedate".equals(tempColumnName)) {
                                    fieldid="-1";
                                }else if ("modedatacreater".equals(tempColumnName)) {
                                    fieldid="-2";
                                }else if ("id".equals(tempColumnName)) {
                                    fieldid="-3";
                                }else if ("modelableid".equals(tempColumnName)) {
                                    fieldid="-4";
                                }else if ("modedatastatus".equals(tempColumnName)) {
                                    fieldid="-5";
                                }else if ("modedatamodifier".equals(tempColumnName)) {
                                    fieldid="-7";
                                }else if ("modedatamodifydatetime".equals(tempColumnName)) {
                                    fieldid="-8";
                                }else if ("seclevel".equals(tempColumnName)) {
                                    fieldid="-9";
                                }
                                if (fieldTransAction!=null&&transFields.contains(fieldid)) {
                                    transMap.put("fieldid", fieldid);
                                    transvalue=fieldTransAction.getTransValue(transMap, user);
                                }else {
                                    if(!StringHelper.isEmpty(tempTransfMethod)&&"weaver.formmode.search.FormModeTransMethod.getDataId".equals(tempTransfMethod)){
                                        transvalue = Util.null2String(data.get(tempColumnName));
                                    }else{
                                        transvalue = Util.useSpecialTreat(tempTransfMethod, Util.null2String(data.get(tempColumnName)),otherpara);
                                    }
                                }
                            } catch (Exception e) {
                                baseBean.writeLog(e);
                            }
                        }else{
                            fieldid = Util.null2String(tempStr[1]);
                            if (fieldTransAction!=null&&transFields.contains(fieldid)) {
                                transMap.put("fieldid", fieldid);
                                transvalue=fieldTransAction.getTransValue(transMap, user);
                            }else {
                                fieldhtmltype = Util.null2String(tempStr[2]);
                                fieldtype = Util.null2String(tempStr[3]);
                                String dbtype = Util.null2String(tempStr[6]);
                                customid = Util.null2String(tempStr[13]);
                                modeid = Util.null2String(tempStr[8]);
                                billid = Util.null2String(tempStr[0]);
                                formid = Util.null2String(tempStr[9]);

                                if(fieldhtmltype.equals("1")){  // 单行
                                    if(fieldhtmltype.equals("1") && fieldtype.equals("2")){//整数
                                        numbertype = 1;
                                        int tempVal = Util.getIntValue(val,-99999999);
                                        if(tempVal!=-99999999){
                                            transvalue = tempVal+"";
                                        }else{
                                            transvalue = "";
                                        }
                                    }else if(fieldhtmltype.equals("1") && fieldtype.equals("4")){//  金额
                                        numbertype = 2;
                                        if(StringHelper.isEmpty(val)){
                                            transvalue = "";
                                        }else{
                                            Pattern pattern = Pattern.compile("^-?(([1-9]\\d*(\\.\\d{1,})?)|(0(\\.\\d{1,})?))$"); //验证浮点数
                                            Matcher isNum = pattern.matcher(val.trim());
                                            if( isNum.matches() ){//非数字
                                                transvalue = val+"";
                                                transvalue = Util.toDecimalDigits(val,2);
                                            }else{
                                                transvalue = "";
                                            }
                                        }
                                    }else if(fieldtype.equals("3")||fieldtype.equals("5")){//浮点数   金额千分位
                                        numbertype = 2;
                                        int decimaldigits_t=0;
                                        if(fieldtype.equals("3")){
                                            int digitsIndex = dbtype.indexOf(",");
                                            if(digitsIndex > -1){
                                                decimaldigits_t = Util.getIntValue(dbtype.substring(digitsIndex+1, dbtype.length()-1), 2);
                                            }else{
                                                decimaldigits_t = 2;
                                            }
                                        }else if(fieldtype.equals("5") ){
//                                            if(!StringHelper.isEmpty(val)){
//                                                val = val.replace(",", "");
//                                            }
                                            int qfws=0;
                                            if(qfwsMap0.containsKey(fieldid)){
                                                qfws = Util.getIntValue(qfwsMap0.get(fieldid),2);
                                            }else{
                                                rs.executeQuery("select qfws from workflow_formdict where id =? " ,fieldid);
                                                if(rs.next()){
                                                    qfws = Util.getIntValue(rs.getString("qfws"),2);
                                                    qfwsMap0.put(fieldid, qfws+"");
                                                }
                                            }
                                            if(qfws==0){
                                                if(qfwsMap1.containsKey(fieldid)){
                                                    qfws=Util.getIntValue(qfwsMap1.get(fieldid),2);
                                                }else{
                                                    RecordSet   rs1=new RecordSet();
                                                    rs1.executeQuery("select qfws from workflow_billfield where id=?",fieldid);
                                                    if(rs1.next()){
                                                        qfws=Util.getIntValue(rs1.getString("qfws"),2);
                                                        if(qfws == -1){
                                                            qfws = 2;
                                                        }
                                                    }
                                                    qfwsMap1.put(fieldid, qfws+"");
                                                }
                                            }
                                            if(qfws <= 0){
                                                qfws = 2;
                                            }
                                            decimaldigits_t = qfws;
                                        }
                                        transvalue = Util.toDecimalDigits(val,decimaldigits_t);

                                        String formatStr = getNumberFormat(decimaldigits_t);
//    	    					        	XSSFDataFormat format =  (XSSFDataFormat) workbook.createDataFormat();
//    	    					        	cellStyle1.setDataFormat(format.getFormat(formatStr));
                                    }else{
                                        transvalue=Util.toHtmlSearch(CubeCipherUitl.decrypt(val));
                                    }
                                }else if(fieldhtmltype.equals("2")){//多行文本框
                                    val = Util.null2String(val);
                                    transvalue = convertTextAreaToExcel(val.replaceAll("</p>\n\n<p>", "\r\n"));
                                }else if(fieldhtmltype.equals("3")){
                                    int userlanguage = 7;
                                    String fieldvalue = val;
                                    // 浏览按钮 (涉及workflow_broswerurl表)
                                    if (fieldtype.equals("2") || fieldtype.equals("19") || fieldtype.equals("402") || fieldtype.equals("403")) {    // 日期和时间
                                        transvalue=fieldvalue;
                                    }else if(fieldtype.equals("290")){  //日期时间
                                        //设置时区信息
                                        TimeZoneVar.setTimeZone(timeZone);
                                        fieldvalue="".equals(Util.null2String(fieldvalue))?"":new DateTransformer().getLocaleDateTime(fieldvalue);
                                        transvalue=fieldvalue;
                                    }else if(!fieldvalue.equals("")) {
                                        String showname = "";                                                   // 值显示的名称
                                        String showid = "";                                                     // 值
                                        ArrayList tempshowidlist=Util.TokenizerString(fieldvalue,",");
                                        if(fieldtype.equals("8") || fieldtype.equals("135")){
                                            //项目，多项目
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname += ProjectInfoComInfo1.getProjectInfoname((String)tempshowidlist.get(k));
                                                }else{
                                                    showname += ProjectInfoComInfo1.getProjectInfoname((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("1") ||fieldtype.equals("17")){
                                            //人员，多人员
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=rc.getResourcename((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=rc.getResourcename((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("7") || fieldtype.equals("18")){
                                            //客户，多客户
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=cci.getCustomerInfoname((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=cci.getCustomerInfoname((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if("4".equals(fieldtype) || "57".equals(fieldtype) || "167".equals(fieldtype) || "168".equals(fieldtype)){
                                            //部门，多部门
                                            OrganizationShowSetBiz orgShowBiz = new OrganizationShowSetBiz();
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=orgShowBiz.getDepartmentShow("model", (String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=orgShowBiz.getDepartmentShow("model", (String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if ("164".equals(fieldtype) || "194".equals(fieldtype) || "169".equals(fieldtype) || "170".equals(fieldtype)) {
                                            // 分部，多分部
                                            OrganizationShowSetBiz orgShowBiz = new OrganizationShowSetBiz();
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=orgShowBiz.getSubcompanyShow("model", (String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=orgShowBiz.getSubcompanyShow("model", (String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("9") || fieldtype.equals("37")){
                                            //文档，多文档
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=DocComInfo1.getDocname((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=DocComInfo1.getDocname((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("22")){ //报销费用类型
                                            FnaSystemSetComInfo fnaSystemSetComInfo = new FnaSystemSetComInfo();
                                            String separator = Util.null2String(fnaSystemSetComInfo.get_separator()).trim();
                                            int enableDispalyAll = Util.getIntValue(fnaSystemSetComInfo.get_enableDispalyAll());
                                            String fullName  = "";
                                            if(enableDispalyAll == 1){
                                                BudgetfeeTypeComInfo budgetfeeTypeComInfo = new BudgetfeeTypeComInfo();
                                                String [] valueArr = fieldvalue.split(",");
                                                for (String keyid : valueArr) {
                                                    fullName = budgetfeeTypeComInfo.getSubjectFullName(keyid, separator);
                                                    showname +=fullName+",";
                                                }
                                                showname = showname.substring(0,showname.length()-1);
                                            }else{
                                                BrowserComInfo bci = new BrowserComInfo();
                                                String tablenamefylx = bci.getBrowsertablename(fieldtype+""); // 浏览框对应的表,比如人力资源表
                                                String columname = bci.getBrowsercolumname(fieldtype+""); // 浏览框对应的表名称字段
                                                String keycolumname = bci.getBrowserkeycolumname(fieldtype+""); // 浏览框对应的表值字段
                                                String bxsql = "select " + keycolumname + "," + columname + " from " + tablenamefylx + " where " + keycolumname + " in ( " + fieldvalue + ")";
                                                rs.executeSql(bxsql);
                                                while (rs.next()) {
                                                    String tempshowname = Util.null2String(rs.getString(2));
                                                    showname +=tempshowname+",";
                                                }
                                                showname = showname.substring(0,showname.length()-1);
                                            }
                                        }else if(fieldtype.equals("16") || fieldtype.equals("152")|| fieldtype.equals("171")){
                                            //相关请求
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=WorkflowRequestComInfo1.getRequestName((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=WorkflowRequestComInfo1.getRequestName((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("141")){
                                            //人力资源条件
                                            showname+=rcm.getFormShowName(fieldvalue,userlanguage);
                                        }
                                        //added by alan for td:10814
                                        else if(fieldtype.equals("142")) {
                                            //收发文单位
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=duc.getReceiveUnitName(""+tempshowidlist.get(k));
                                                }else{
                                                    showname+=duc.getReceiveUnitName(""+tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }
                                        else if(fieldtype.equals("161")){//自定义单选
                                            showname = "";                                   // 新建时候默认值显示的名称
                                            showid =fieldvalue;
                                            if(!StringHelper.isEmpty(showid)){
                                                HashMap<String, String> browsers = browserMap.get(dbtype);
                                                if(browsers == null) {
                                                    browsers = new HashMap<String, String>();
                                                    browserMap.put(dbtype, browsers);
                                                }
                                                if(browsers.containsKey(showid)){
                                                    showname+=browsers.get(showid)+" ";
                                                }else{
                                                    try{
                                                        Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(dbtype);
                                                        List<String> castList = ModeCacheManager.getInstance().getBrowserShowNameById(dbtype, showid,user.getLanguage());
                                                        String name = "";
                                                        if(castList.size()==1){
                                                            name = castList.get(0);
                                                        }else{
                                                            BrowserBean bb=browser.searchById(showid);
                                                            name=Util.null2String(bb.getName());
                                                        }
                                                        if(isReturnDecryptData){
                                                            name = EncryptConfigBiz.getDecryptData(name);
                                                        }
                                                        browsers.put(showid, name);
                                                        showname+=name+" ";
                                                    }catch(Exception e){
                                                        e.printStackTrace();
                                                    }
                                                }
                                            }
                                        }
                                        else if(fieldtype.equals("162")){//自定义多选
                                            showname = "";                                  // 新建时候默认值显示的名称
                                            showid =fieldvalue;                                     // 新建时候默认值
                                            HashMap<String, String> browsers = browserMap.get(dbtype);
                                            if(browsers == null) {
                                                browsers = new HashMap<String, String>();
                                                browserMap.put(dbtype, browsers);
                                            }
                                            try{
                                                Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(dbtype);
                                                List l=Util.TokenizerString(showid,",");
                                                List<String> castList = ModeCacheManager.getInstance().getBrowserShowNameById(dbtype, showid,user.getLanguage());
                                                for(int j=0;j<l.size();j++){
                                                    String curid=(String)l.get(j);
                                                    String name = "";
                                                    if(castList.size()==l.size()){
                                                        name = castList.get(j);
                                                    }else{
                                                        BrowserBean bb=browser.searchById(curid);
                                                        name=Util.null2String(bb.getName());
                                                    }
                                                    if(isReturnDecryptData){
                                                        name = EncryptConfigBiz.getDecryptData(name);
                                                    }
                                                    browsers.put(curid, name);
                                                    showname+=name+",";
                                                }
                                                if(!"".equals(showname)){
                                                    showname=showname.substring(0,showname.length()-1);
                                                }
                                            }catch(Exception e){
                                            }
                                        }else if (fieldtype.equals("256")||fieldtype.equals("257")) {//自定义树形单选
                                            CustomTreeUtil customTreeUtil = new CustomTreeUtil();
                                            customTreeUtil.setReturnDecryptData(isReturnDecryptData);
                                            showid = fieldvalue;
                                            showname+=customTreeUtil.getTreeFieldShowName(fieldvalue,dbtype,"onlyname");
                                        }else if(fieldtype.equals("226")){//sap浏览框
                                            showname=fieldvalue;
                                        }else  if(fieldtype.equals("298")){//账套
                                            showname=new AccountInfoComInfo().getAccountName(fieldvalue);
                                        }else if(fieldtype.equals("263")){
                                            // TODO: 2022/1/27 待完成数据导出区县
                                            showname = getProvinceNameAndAreaBy(fieldvalue);
                                        }else{
                                            String tablename=BrowserComInfo.getBrowsertablename(fieldtype); //浏览框对应的表,比如人力资源表
                                            String columname=BrowserComInfo.getBrowsercolumname(fieldtype); //浏览框对应的表名称字段
                                            String keycolumname=BrowserComInfo.getBrowserkeycolumname(fieldtype);   //浏览框对应的表值字段
                                            fieldvalue=formModeTransMethod.deleteFirstAndEndchar(fieldvalue,",");
                                            if(tablename.equals("HrmResource")){
                                                tablename="HrmResourceAllView";
                                            }
                                            if(fieldvalue.indexOf(",")!=-1){
                                                sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+" in( "+fieldvalue+")";
                                            }else {
                                                sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+"="+fieldvalue;
                                            }
                                            RecordSet.execute(sql);
                                            while(RecordSet.next()){
                                                showname+=Util.toScreen(RecordSet.getString(2),userlanguage)+",";
                                            }
                                            if(!"".equals(showname)){
                                                showname=showname.substring(0,showname.length()-1);
                                            }
                                        }
                                        transvalue=Util.formatMultiLang(showname.toString(),user.getLanguage()+"");
                                    }

                                }else if(fieldhtmltype.equals("4")) {                    // check框
                                    transvalue=val;
                                }else if(fieldhtmltype.equals("5")){
                                    String key = fieldid+"_"+val;
                                    if(selectMap.containsKey(key)){
                                        transvalue = selectMap.get(key);
                                    }else{
                                        // 查询选择框的所有可以选择的值
                                        //根据fieldid 判断是否是密级字段如果是调用人力资源那边的工具类返回对应的信息
                                        String sqlQueryIsSeclevel = " select count(1) as count from WORKFLOW_BILLFIELD where id = "+fieldid +" and fieldname='seclevel' ";
                                        RecordSet rsQuerySeclevel = new RecordSet();
                                        boolean queryIsSeclevelFlag = rsQuerySeclevel.executeSql(sqlQueryIsSeclevel);
                                        int seclevelCount = 0;
                                        if(queryIsSeclevelFlag && rsQuerySeclevel.next()){
                                            seclevelCount =Util.getIntValue(rsQuerySeclevel.getString("count"));
                                        }
                                        if(seclevelCount>0){
                                            Map<String, Object> param = new HashMap<>();
                                            param.put("selectMap", selectMap);
                                            param.put("userlanguage", user.getLanguage());
                                            param.put("fieldvalue", val);
                                            AddSeclevelUtil addSeclevelUtil = new AddSeclevelUtil();
                                            transvalue= addSeclevelUtil.getSeclevelOptionForExp(param);


                                        }else{

                                            if(fieldtype.equals("2")||val.indexOf(",")>-1){  // 复选框
                                                ArrayList tempvalues = Util.TokenizerString(val,",");
                                                List<String> list = ModeCacheManager.getInstance().getSelectShowNameById(fieldid, val, user.getLanguage());
                                                for (int j = 0; j < tempvalues.size(); j++) {
                                                    String selectvalue=(String)tempvalues.get(j);
                                                    String value = "";
                                                    if(list.size()==tempvalues.size()){
                                                        value = list.get(j);
                                                    }else{
                                                        rs.execute(" select selectname from workflow_selectitem where fieldid='"+fieldid+"' and selectvalue='"+selectvalue+"'" );
                                                        if(rs.next()){
                                                            value=rs.getString("selectname");
                                                        }
                                                    }
                                                    transvalue+=value+",";
                                                }
                                                if(!"".equals(transvalue)){
                                                    transvalue=transvalue.substring(0,transvalue.length()-1);
                                                }
                                                selectMap.put(fieldid+"_"+val, transvalue);
                                            }else{
                                                List<String> list = ModeCacheManager.getInstance().getSelectShowNameById(fieldid, val, user.getLanguage());
                                                if(list.size()>0){
                                                    transvalue=list.get(0);
                                                    selectMap.put(fieldid+"_"+val, transvalue);
                                                }else{
                                                    rs.execute(" select selectvalue,selectname from workflow_selectitem where fieldid='"+fieldid+"'");
                                                    while(rs.next()){
                                                        String selvalue = rs.getString("selectvalue");
                                                        String selname = rs.getString("selectname");
                                                        selectMap.put(fieldid+"_"+selvalue, selname);
                                                        if(val.equals(selvalue)){
                                                            transvalue = selname;
                                                        }
                                                    }
                                                }

                                            }
                                        }
                                    }
                                } else if(fieldhtmltype.equals("7")){ //特殊字段
                                    RecordSet rs1 = new RecordSet();
                                    rs1.executeQuery("select linkaddress,descriptivetext from workflow_specialfield where fieldid =? and isbill = 1",fieldid);
                                    if("1".equals(fieldtype)){ //自定义链接
                                        while(rs1.next()){
                                            transvalue = Util.null2String(rs1.getString("linkaddress"));
                                        }
                                    } else if("2".equals(fieldtype)){//描述性文字
                                        while(rs1.next()){
                                            transvalue = Util.null2String(rs1.getString("descriptivetext"));
                                            if (transvalue.contains("<br>")){
                                                transvalue = transvalue.replaceAll("<br>", "\r\n");
                                            }
                                        }
                                    }
                                }else{
                                    try {
                                        transvalue = Util.useSpecialTreat(tempTransfMethod, Util.null2String(data.get(tempColumnName)),otherpara);
                                        transvalue = Util.HTMLtoTxt(transvalue);
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        }

                    }

                    //如果查询列表显示的条形码，则导出excle的时候对应的字段也要是条形码格式
                    String tempsql = "";
                    if(barcodeMap.containsKey(modeid)){
                        Map<String,String> m=barcodeMap.get(modeid);
                        isUsed=m.get("isUsed");
                        codenum=m.get("codenum");
                    }else{
                        boolean modeIdIsNum = false;
                        Pattern patternisNum = Pattern.compile("^-?[0-9]+");
                        Matcher isNum = patternisNum.matcher(modeid);
                        if(isNum.matches() ){
                            modeIdIsNum=true;
                        }

                        if("".equals(isUsed) && !modeid.equals("")&&modeIdIsNum){
                            tempsql = "select * from mode_barcode where modeid=?";
                            RecordSet.executeQuery(tempsql,modeid);
                            if(RecordSet.next()){
                                isUsed = RecordSet.getString("isused");
                                codenum = RecordSet.getString("codenum");
                            }
                        }
                        Map<String,String> m=new HashMap<String, String>();
                        m.put("isUsed", isUsed);
                        m.put("codenum", codenum);
                        barcodeMap.put(modeid, m);
                    }
                    if("1".equals(isUsed)){
                        tempsql = "select * from customfieldshowchange where customid=? and fieldid=?";
                        RecordSet.executeQuery(tempsql,customid,fieldid);
                        if(RecordSet.next()){
                            String fieldShowValue = RecordSet.getString("fieldshowvalue");
                            if("#BARCodeImg#".equals(fieldShowValue)){
                                String tempnum = "";
                                if(codenum == null || "".equals(codenum)){
                                    tempnum = " ";
                                }else{
                                    tempnum = BarcodeHandler.replaceField(user,codenum,modeid,billid,formid);
                                }
                                transvalue = tempnum;
                                barFlag = false;
                                if(flag){
                                    infoindex.add(i+1); //如果第一列为统计字段，则需要将index+1
                                }else{
                                    infoindex.add(i); //添加索引
                                }
                            }
                        }
                    }


                    try {
                        if("1".equals(iscustomsearch)){
                            StringBuffer sb = new StringBuffer();
                            Pattern pattern = Pattern.compile("<[aA]*[^>]+?>([^<]*)</[aA]>");
                            Matcher matcher = pattern.matcher(transvalue);
                            while(matcher.find()){
                                String s = matcher.group(1);
                                matcher.appendReplacement(sb, s);
                            }
                            matcher.appendTail(sb);
                            transvalue = sb.toString();
                        }else{
                            transvalue = Util.replace(transvalue,"<[^>]+>","",0);
                        }
                        transvalue = Util.replace(transvalue,"&nbsp;"," ",0);
                        transvalue = Util.replace(transvalue,"&nbsp"," ",0);
                        transvalue = transvalue.trim();
                        String[] transvalue1 = 	transvalue.split(" ");//QC697548,若查询数据为加密状态则解密。对于自定义多选则需要分割字符串并解密。
                        String str1 = "";
                        for(String str : transvalue1){
                            if(str.indexOf("cube~cipher~start")>-1 && !"".equals(str)){
                                str1 += " " + CubeCipherUitl.decrypt(str);
                                transvalue = str1;
                            }
                        }
                        transvalue = Util.processBody(transvalue, Util.null2String(Util.null2String(user.getLanguage()),"7"));
                    } catch (Exception e) {
                        baseBean.writeLog(e);
                    }
                    cell=row.createCell(flag?(i+1):i);
                    cellStyle.setWrapText(true);//自动换行
                    cell.setCellStyle(cellStyle);
                    if(numbertype==1 && barFlag){
                        if(StringHelper.isEmpty(transvalue)){
                            cell.setCellValue("");
                        }else{
                            int tempvalue = Util.getIntValue(transvalue);

                            if(isformat(fieldid,customid,tempvalue+"")||transvalue.replace(".","").length()>15){
                                cell.setCellValue(formatNumber(fieldid,customid,transvalue,billid,formid));
                            }else{
                                cell.setCellType(CellType.NUMERIC);
                                cell.setCellValue( Util.getIntValue(formatNumber(fieldid,customid,tempvalue+"",billid,formid)));
                            }
                        }
                    }else if(numbertype==2 && barFlag){
                        if(StringHelper.isEmpty(transvalue)){
                            cell.setCellValue("");
                        }else{
                            //double tempvalue = Util.getDoubleValue(transvalue) ;
                            //if(tempvalue != 0.0){
                            String[] tempStr = Util.TokenizerString2(otherpara, "+");//浮点数导出时，设置自定义单元格格式
                            fieldhtmltype = Util.null2String(tempStr[2]);
                            fieldtype = Util.null2String(tempStr[3]);
                            String dbtype = Util.null2String(tempStr[6]);
                            int digitsIndex = dbtype.indexOf(",");
                            int decimaldigits_t = 0;
                            if(digitsIndex > -1){
                                decimaldigits_t = Util.getIntValue(dbtype.substring(digitsIndex+1, dbtype.length()-1), 2);
                            }else{
                                decimaldigits_t = 2;
                            }
                            if("1".equals(fieldhtmltype) && "5".equals(fieldtype)){//金额千分位从数据库查小数位数
                                RecordSet rs1 = new RecordSet();
                                rs1.executeQuery("select qfws from workflow_billfield where id=?",fieldid);
                                while(rs1.next()){
                                    decimaldigits_t = rs1.getInt("qfws");
                                }
                            }
                            CellStyle floatStyle = this.getFloatStyle(decimaldigits_t, workbook, rowindex);
//							String formatStr = getNumberFormat(decimaldigits_t);
////							XSSFDataFormat format =  (XSSFDataFormat) workbook.createDataFormat();
////							cellStyle1.setDataFormat(format.getFormat(formatStr));
//							XSSFDataFormat format =  (XSSFDataFormat) workbook.createDataFormat();
//							cellStyle.setDataFormat(format.getFormat(formatStr));
                            cell.setCellValue(formatNumber(fieldid,customid,transvalue,billid,formid));
                            if(transvalue.replace(".","").length()<=15 && !("1".equals(fieldhtmltype) && "5".equals(fieldtype))){
                                //getDoubleValue位数太长会转成科学计数法，导致isformat()判断有问题
                                if(isformat(fieldid,customid,transvalue)){
                                    cell.setCellValue(formatNumber(fieldid,customid,transvalue,billid,formid));
                                }else {
                                    cell.setCellType(CellType.NUMERIC);
                                    cell.setCellValue(Util.getDoubleValue(formatNumber(fieldid,customid,transvalue,billid,formid),decimaldigits_t));
                                }
                            }else{
                                cell.setCellValue(formatNumber(fieldid,customid,transvalue,billid,formid));
                            }
                            cell.setCellStyle(floatStyle);
                            //}
                        }
                    }else{
                        cell.setCellValue(transvalue);
                    }
//					cell.setCellStyle(cellStyle1);

                }
                rowindex++;
            }
            if(!"".equals(countColumns)&&havedata){
                //添加统计行
                SXSSFRow row = sheet.createRow(rowindex);
                XSSFCellStyle cellStyle = rowindex%2==0?doubleStyle:singleStyle;

                SXSSFCell cell;
                if(flag){
                    cell=row.createCell(0);
                    cell.setCellStyle(cellStyle);
                    cell.setCellValue(SystemEnv.getHtmlLabelName(523,user.getLanguage()));//总计
                }

                for(int j=0;j<columnList.size(); j++){
                    XSSFCellStyle cellStyle1 = (XSSFCellStyle) workbook.createCellStyle();
                    cellStyle1 = getCellStyle(cellStyle1,rowindex);
                    String customid = modeCustomid;
                    String fieldid = "";
                    String fieldsql = "select id from workflow_billfield where billid =(select formid from mode_customsearch mc where id=?) and lower(fieldname)  = ?";
                    RecordSet rds= new RecordSet();
                    rds.executeQuery(fieldsql,customid,columnList.get(j).toLowerCase());
                    if(rds.next()){
                        fieldid = Util.null2String(rds.getString(1));
                    }
                    String value = "";
                    int numbertype = 0;
                    if(!flag&&j==0){
                        value = SystemEnv.getHtmlLabelName(523,user.getLanguage());//总计
                    }
                    String column = (String) columnList.get(j);
                    if(Util.contains(countColumnArr, column)||Util.contains(countColumnArr, column.toUpperCase())||Util.contains(countColumnArr, column.toLowerCase())){
                        value = Util.null2String(""+countCV.get(column));
                        if(value.equalsIgnoreCase("null") || value.equals("")){
                            value = "0";
                        }else{
                            String decimal = Util.null2String(decimalCV.get(column));
                            if(!decimal.equals("")){
                                numbertype = decimal.equals("%.0f") ? 1 : 2;
                                value = String.format(decimal, Util.getDoubleValue(value,0));
                                int qfw = Util.getIntValue(decimal.replace("%.", "").replace("f", ""),0);
                                String formatStr = getNumberFormat(qfw);
                                XSSFDataFormat format =  (XSSFDataFormat) workbook.createDataFormat();
                                cellStyle1.setDataFormat(format.getFormat(formatStr));
                            }else{
                                value = String.format("%.0f", Util.getDoubleValue(value,0));
                            }
                            if (countColumnsDbType!=null && countColumnsDbType.size()>0) {
                                if (countColumnsDbType.get(column.toLowerCase())!=null) {
                                    if (countColumnsDbType.get(column.toLowerCase())==1) {
                                        String toObtainValue = Util.null2String(""+countCV.get(column));
                                        if (toObtainValue.indexOf(".")>-1) {
                                            String digits = toObtainValue.substring(toObtainValue.indexOf(".")+1, toObtainValue.length());
                                            if (digits.length()==1 && Util.getIntValue(digits, 0)==0) {
                                                value =  NumberHelper.moneyAddCommaNotDeci(toObtainValue);
                                            }else {
                                                value = NumberHelper.moneyAddCommaSub(toObtainValue);
                                            }
                                        }else {
                                            value = NumberHelper.moneyAddCommaNotDeci(toObtainValue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    cell=row.createCell(flag?(j+1):j);
                    if(numbertype==1){
                        if(StringHelper.isEmpty(value)){
                            cell.setCellValue("");
                        }else{
                            value = formatNumber(fieldid,customid,value,"","");
                            int valuei=Util.getIntValue(value);
                            if(valuei == -1){
                                cell.setCellValue(value);
                            }else{
                                cell.setCellValue(valuei);
                            }
                        }
                    }else if(numbertype==2){
                        if(StringHelper.isEmpty(value)){
                            cell.setCellValue("");
                        }else{
                            if("1".equals(iscustomsearch)){
                                value = value.replace(",", "");
                                value = String.format(Util.null2String(decimalCV.get(column)), Util.getDoubleValue(value,0));
                            }
                            double tempvalue = Util.getDoubleValue(value) ;
                            //if(tempvalue != 0.0){
                            BigDecimal b = new BigDecimal(tempvalue);
                            String tempvaluestr=String.valueOf(b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            tempvaluestr = formatNumber(fieldid,customid,tempvaluestr,"","");
                            cell.setCellValue(tempvaluestr) ;
                            //}
                        }
                    }else {
                        value = formatNumber(fieldid,customid,value,"","");
                        cell.setCellValue(value);
                    }
                    cell.setCellStyle(cellStyle1);
                }
            }
        } catch (Exception e) {
            baseBean.writeLog(e);
        } finally {
            String endtime = DateHelper.getCurDateTime();
            long endt = new Date().getTime();
            long l = endt - begin;
            baseBean.writeLog("excel列表导出：耗时毫秒数："+l+",时间范围：["+starttime+" -至- "+endtime+" ]");
        }
    }

    /**
     * 新增金额大写、千分位逻辑
     * @param fieldid
     * @param customid
     * @param val
     * @return
     */
    private String formatNumber(String fieldid, String customid, String val,String billid,String formid) {
        RecordSet rs = new RecordSet();
        RecordSet rs1= new RecordSet();
        String sql = "select fieldshowvalue,conditionsql from customfieldshowchange WHERE customid=? and fieldid=?";
        rs.executeQuery(sql, customid, fieldid);
        if(formid != ""){
            String formSql = "select tablename from workflow_bill where id=?";
            rs1.executeQuery(formSql,formid);
        }

        String tablename = "";
        if(rs1.next()){
            tablename = Util.null2String(rs1.getString(1));
        }
        if (rs.next()) {
            String transFunction = Util.null2String(rs.getString(1));
            String conditionsql = Util.null2String(rs.getString(2));
            conditionsql = StringUtil.isEmpty(conditionsql)?"":"and ("+conditionsql+")";
            if(billid!=""){
                String querySql = "select id from "+tablename+" where id =? "+conditionsql;
                rs1.executeQuery(querySql,billid);
            }

            if(rs1.next()||(billid==""&&formid==""&&StringUtil.isEmpty(conditionsql))){
                if (!"".equals(transFunction)) {
                    if (transFunction.contains("Amount(")) {
                        val = CubeSearchTransMethod.INSTANCE.NumToChinese(val);
                    } else if (transFunction.contains("Thousands(")) {
                        val = CubeSearchTransMethod.INSTANCE.changeToThousands(val);
                    }
                }
            }
        }
        return val;
    }

    /**
     * 当前字段值是否格式化了
     * @param fieldid
     * @param customid
     * @param val
     * @return
     */
    private boolean isformat(String fieldid, String customid, String val) {
        boolean isformat = false;
        RecordSet rs = new RecordSet();
        String sql = "select fieldshowvalue from customfieldshowchange WHERE customid=? and fieldid=?";
        rs.executeQuery(sql, customid, fieldid);
        if (rs.next()) {
            val = val.replace("-","");
            if(val.indexOf(".")>-1){
                val = val.substring(0,val.indexOf("."));
            }
            String transFunction = Util.null2String(rs.getString(1));
            if (!"".equals(transFunction)) {
                //金额大写
                if (transFunction.contains("Amount(")) {
                    isformat = true;
                } else if (transFunction.contains("Thousands(")&&val.length()>3) {
                    isformat = true;
                }
            }
        }
        return isformat;
    }

    /**
     * 获取浮点数样式(在单双行的基础上设置,不能全部通过workbook重新创造,一个excle容纳的CellStyle最多为4000)
     *
     * @param qfws     浮点数位数
     * @param workbook
     * @param rowindex 行号
     * @return
     */
    private CellStyle getFloatStyle(int qfws,Workbook workbook,int rowindex){
        String style=rowindex%2==0?"doubleStyle":"singleStyle";
        if (allstyle.containsKey(style+"_qfws"+qfws)) {
            return allstyle.get(style+"_qfws"+qfws);
        }
        //获取单双行样式(不可以在该样式上直接设置浮点数样式,这两个样式是全局共用的,设置了浮点数样式会覆盖,先拷贝一份再设置)
        XSSFCellStyle baseStyle = allstyle.get(style);
        CellStyle newStyle = workbook.createCellStyle();
        copyStyle((XSSFCellStyle)newStyle, baseStyle);
        String formatStr = getNumberFormat(qfws);
        XSSFDataFormat format =  (XSSFDataFormat) workbook.createDataFormat();
        newStyle.setDataFormat(format.getFormat(formatStr));
        allstyle.put(style+"_qfws"+qfws, (XSSFCellStyle)newStyle);
        return newStyle;
    }

    /**
     * 拷贝单双行样式
     * @param newStyle
     * @param oldStyle
     */
    private void copyStyle(XSSFCellStyle newStyle,XSSFCellStyle oldStyle){
        newStyle.setFillForegroundColor(oldStyle.getFillForegroundXSSFColor());
        newStyle.setFillPattern(oldStyle.getFillPattern());
        newStyle.setFont(oldStyle.getFont());
        newStyle.setAlignment(oldStyle.getAlignment());//内容对齐方式
        newStyle.setBorderColor(BorderSide.BOTTOM, oldStyle.getBorderColor(BorderSide.BOTTOM));
        newStyle.setBorderColor(BorderSide.LEFT, oldStyle.getBorderColor(BorderSide.LEFT));
        newStyle.setBorderColor(BorderSide.RIGHT, oldStyle.getBorderColor(BorderSide.RIGHT));
        newStyle.setBorderColor(BorderSide.TOP, oldStyle.getBorderColor(BorderSide.TOP));
        newStyle.setBorderBottom(oldStyle.getBorderBottom());
        newStyle.setBorderLeft(oldStyle.getBorderLeft());
        newStyle.setBorderRight(oldStyle.getBorderRight());
        newStyle.setBorderTop(oldStyle.getBorderTop());
    }

    /**
     * 通过小数位数获取数字格式
     *
     * @param qfw
     * @return
     */
    public String getNumberFormat(int qfw) {
        String formatStr = "0";									//设置数字格式
        for(int fi = 0 ; fi < qfw ; fi++)				//判断小数位数   设置数字显示格式  例如0.00
        {	if(fi == 0){ 	formatStr += "." ;	}
            formatStr += "0";
        }
        return formatStr;

    }

    /**
     * 多行文本输出到excle中需要去掉html、script标签
     * @param value
     * @return
     */
    private String convertTextAreaToExcel(String value){
        String tempString = value;
        //对转义的特殊字符进行替换.
        tempString = tempString.replaceAll("&lsquo;","‘");//中文左双引号
        tempString = tempString.replaceAll("&rsquo;","’");//中文右双引号
        tempString = tempString.replaceAll("&#39;","'");//英文单引号
        tempString = tempString.replaceAll("&ldquo;","“");//中文左双引号
        tempString = tempString.replaceAll("&rdquo;","”");//中文右双引号
        tempString = tempString.replaceAll("&quot;","\"");//英文双引号
        tempString = tempString.replaceAll("&gt;",">");//大于号
        tempString = tempString.replaceAll("&lt;", "<");//小于号
        tempString = tempString.replaceAll("&mdash;", "—");//破折号(一半)
        tempString = tempString.replaceAll("&hellip;", "…");//省略号(一半)
        tempString = tempString.replaceAll("&middot;", "·");//中点
        tempString = tempString.replaceAll("&nbsp;", " ");//空格

        tempString = tempString.replaceAll("<[pP]+[^><]*>", "\r\n");
        tempString = tempString.replaceAll("</[pP]+>", "\r\n");
        tempString = tempString.replaceAll("(?i)<br\\s*/?>","\r\n");
        tempString = tempString.replaceAll("<script[^>]*?>.*?</script>","");
        tempString = Util.HTMLtoTxt(tempString);
        return tempString;
    }

    /**
     * 样式定义
     * @param ef
     */
    private void initStyle(SXSSFWorkbook wb) {
        XSSFCellStyle headerStyle = (XSSFCellStyle) wb.createCellStyle();//头部样式
        XSSFCellStyle singleStyle = (XSSFCellStyle) wb.createCellStyle();//单行样式
        XSSFCellStyle doubleStyle = (XSSFCellStyle) wb.createCellStyle();//双行行样式
        IndexedColorMap map = new DefaultIndexedColorMap();
        //没有设置自定义样式导出时
        String headerbg = "#585858";//默认头部背景色
        String headerfontcolor ="#ffffff";//默认头部字体颜色 白色
        String headerfont =  "Arial";//头部字体
        String headerfontsize = "10";//头部字体大小
        HorizontalAlignment headertextalign = HorizontalAlignment.CENTER;//头部对齐方式  居中
        //内容设置
        String contentfontcolor = "#000000";//内容字体颜色 黑色
        String contentdoublerowbg = "#F2F2F2";//内容双行背景色
        String contentsinglerowbg = "#ffffff";//内容单行背景色
        String contentfont ="Arial";//内容字体
        String contentfontsize = "10";//内容字体大小
        HorizontalAlignment contenttextalgin = HorizontalAlignment.LEFT;//内容对齐方式 左对齐
        String gridlinewidth ="1";//边框线样式
        String gridlinecolor = "#D8D8D8";//边框线颜色
        if (iscustomstyle) {//如果自定义样式
            RecordSet rs =new RecordSet();
            String sql = "select * from mode_exportcustomstyle where customid=?";
            rs.executeQuery(sql,modeCustomid);
            if(rs.next()){
                headerbg = Util.null2s(rs.getString("headerbg"),"#808080");//头部背景色
                headerfontcolor = Util.null2s(rs.getString("headerfontcolor"),"#000000");//头部字体颜色
                headerfont =  Util.null2s(rs.getString("headerfont"),"Arial");//头部字体
                headerfontsize = Util.null2s(rs.getString("headerfontsize"),"10");//头部字体大小
                String headertextalignval = Util.null2s(rs.getString("headertextalign"),"2");//头部对齐方式
                headertextalign=getAlignment(headertextalignval);
                //内容设置
                contentfontcolor = Util.null2s(rs.getString("contentfontcolor"),"#000000");//内容字体颜色
                contentdoublerowbg = Util.null2s(rs.getString("contentdoublerowbg"),"#C0C0C0");//内容双行背景色
                contentsinglerowbg = Util.null2s(rs.getString("contentsinglerowbg"),"#ffffff");//内容单行背景色
                contentfont = Util.null2s(rs.getString("contentfont"),"Arial");//内容字体
                contentfontsize = Util.null2s(rs.getString("contentfontsize"),"10");//内容字体大小
                String contenttextalginval = Util.null2s(rs.getString("contenttextalgin"),"2");//内容对齐方式
                contenttextalgin=getAlignment(contenttextalginval);
                gridlinewidth = Util.null2s(rs.getString("gridlinewidth"),"1");//边框线样式
                gridlinecolor = Util.null2s(rs.getString("gridlinecolor"),"#000000");//边框线颜色
            }
        }
        //头部
        Color color = Color.decode(headerbg); // 标题列背景色
        XSSFColor xSSFColor=new XSSFColor(color,map);
        headerStyle.setFillForegroundColor(xSSFColor);
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        XSSFFont headerFont = (XSSFFont) wb.createFont();
        color = Color.decode(headerfontcolor);
        xSSFColor=new XSSFColor(color,map);
        headerFont.setBold(true);//标题默认加粗
        headerFont.setFontName(headerfont);//标题字体
        headerFont.setFontHeightInPoints(Short.parseShort(headerfontsize));//标题字体大小
        headerFont.setColor(xSSFColor);// 标题字体颜色
        headerStyle.setAlignment(headertextalign);//标题对齐方式
        headerStyle.setFont(headerFont);
        color = Color.decode(gridlinecolor); //边框线颜色
        XSSFColor borderColor = new XSSFColor(color,map);
        setBorder(headerStyle, borderColor, Short.parseShort(gridlinewidth));//边框线颜色样式

        //单行样式
        color = Color.decode(contentsinglerowbg); //单行背景色
        xSSFColor=new XSSFColor(color,map);
        singleStyle.setFillForegroundColor(xSSFColor);
        singleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //双行样式
        color = Color.decode(contentdoublerowbg); //双行背景色白色
        xSSFColor=new XSSFColor(color,map);
        doubleStyle.setFillForegroundColor(xSSFColor);
        doubleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //内容样式
        XSSFFont contentFont = (XSSFFont) wb.createFont();
        color =Color.decode(contentfontcolor); // 内容列字体颜色
        xSSFColor=new XSSFColor(color,map);
        contentFont.setColor(xSSFColor);
        contentFont.setFontName(contentfont);//内容字体
        contentFont.setFontHeightInPoints(Short.parseShort(contentfontsize));//内容字体大小
        singleStyle.setFont(contentFont);
        doubleStyle.setFont(contentFont);
        singleStyle.setAlignment(contenttextalgin);//内容对齐方式
        doubleStyle.setAlignment(contenttextalgin);//内容对齐方式
        color =Color.decode(gridlinecolor); // 边框颜色
        xSSFColor=new XSSFColor(color,map);
        setBorder(singleStyle, xSSFColor, Short.parseShort(gridlinewidth));//设置边框线
        setBorder(doubleStyle, xSSFColor, Short.parseShort(gridlinewidth));//设置边框线
        allstyle.put("headerStyle", headerStyle);
        allstyle.put("singleStyle", singleStyle);
        allstyle.put("doubleStyle", doubleStyle);
    }

    public XSSFCellStyle getCellStyle(XSSFCellStyle cellStyle,int rowindex) {
        SXSSFWorkbook wb = new SXSSFWorkbook();
/*		IndexedColorMap map = new DefaultIndexedColorMap();
		//内容设置
		String contentfontcolor = "#000000";//内容字体颜色 黑色
		String contentdoublerowbg = "#F2F2F2";//内容双行背景色
		String contentsinglerowbg = "#ffffff";//内容单行背景色
		String contentfont ="Arial";//内容字体
		String contentfontsize = "10";//内容字体大小
		HorizontalAlignment contenttextalgin = HorizontalAlignment.RIGHT;//内容对齐方式 右对齐
		String gridlinewidth ="1";//边框线样式
		String gridlinecolor = "#D8D8D8";//边框线颜色
		if (iscustomstyle) {//如果自定义样式
			RecordSet rs =new RecordSet();
			String sql = "select * from mode_exportcustomstyle where customid=?";
			rs.executeQuery(sql,modeCustomid);
			if(rs.next()){
				//内容设置
				contentfontcolor = Util.null2s(rs.getString("contentfontcolor"),"#000000");//内容字体颜色
				contentdoublerowbg = Util.null2s(rs.getString("contentdoublerowbg"),"#C0C0C0");//内容双行背景色
				contentsinglerowbg = Util.null2s(rs.getString("contentsinglerowbg"),"#ffffff");//内容单行背景色
				contentfont = Util.null2s(rs.getString("contentfont"),"Arial");//内容字体
				contentfontsize = Util.null2s(rs.getString("contentfontsize"),"10");//内容字体大小
				String contenttextalginval = Util.null2s(rs.getString("contenttextalgin"),"2");//内容对齐方式
				contenttextalgin=getAlignment(contenttextalginval);
				gridlinewidth = Util.null2s(rs.getString("gridlinewidth"),"1");//边框线样式
				gridlinecolor = Util.null2s(rs.getString("gridlinecolor"),"#000000");//边框线颜色
			}
		}

		//单行样式
		Color color = Color.decode(contentsinglerowbg); //单行背景色
		XSSFColor xSSFColor=new XSSFColor(color,map);
		if(rowindex%2 == 0){
			//双行样式
			color = Color.decode(contentdoublerowbg); //双行背景色白色
			xSSFColor=new XSSFColor(color,map);
		}
		cellStyle.setFillForegroundColor(xSSFColor);
		cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

		//内容样式
		XSSFFont contentFont = (XSSFFont) wb.createFont();
		color =Color.decode(contentfontcolor); // 内容列字体颜色
		xSSFColor=new XSSFColor(color,map);
		contentFont.setColor(xSSFColor);
		contentFont.setFontName(contentfont);//内容字体
		contentFont.setFontHeightInPoints(Short.parseShort(contentfontsize));//内容字体大小
		cellStyle.setFont(contentFont);
		//doubleStyle.setFont(contentFont);
		cellStyle.setAlignment(contenttextalgin);//内容对齐方式
		//doubleStyle.setAlignment(contenttextalgin);//内容对齐方式
		color =Color.decode(gridlinecolor); // 边框颜色
		xSSFColor=new XSSFColor(color,map);
		setBorder(cellStyle, xSSFColor, Short.parseShort(gridlinewidth));//设置边框线
		//setBorder(doubleStyle, xSSFColor, Short.parseShort(gridlinewidth));//设置边框线
		return cellStyle;*/


        IndexedColorMap map = new DefaultIndexedColorMap();
        //内容设置
        String contentfontcolor = "#000000";//内容字体颜色 黑色
        String contentdoublerowbg = "#F2F2F2";//内容双行背景色
        String contentsinglerowbg = "#ffffff";//内容单行背景色
        String contentfont ="Arial";//内容字体
        String contentfontsize = "10";//内容字体大小
        HorizontalAlignment contenttextalgin = HorizontalAlignment.RIGHT;//内容对齐方式 右对齐
        String gridlinewidth ="1";//边框线样式
        String gridlinecolor = "#D8D8D8";//边框线颜色
        if (iscustomstyle) {//如果自定义样式
            RecordSet rs =new RecordSet();
            String sql = "select * from mode_exportcustomstyle where customid=?";
            rs.executeQuery(sql,modeCustomid);
            if(rs.next()){
                //内容设置
                contentfontcolor = Util.null2s(rs.getString("contentfontcolor"),"#000000");//内容字体颜色
                contentdoublerowbg = Util.null2s(rs.getString("contentdoublerowbg"),"#C0C0C0");//内容双行背景色
                contentsinglerowbg = Util.null2s(rs.getString("contentsinglerowbg"),"#ffffff");//内容单行背景色
                contentfont = Util.null2s(rs.getString("contentfont"),"Arial");//内容字体
                contentfontsize = Util.null2s(rs.getString("contentfontsize"),"10");//内容字体大小
                String contenttextalginval = Util.null2s(rs.getString("contenttextalgin"),"2");//内容对齐方式
                contenttextalgin=getAlignment(contenttextalginval);
                gridlinewidth = Util.null2s(rs.getString("gridlinewidth"),"1");//边框线样式
                gridlinecolor = Util.null2s(rs.getString("gridlinecolor"),"#000000");//边框线颜色
            }
        }
        Color color = Color.decode(contentsinglerowbg); // 标题列背景色
        XSSFColor xSSFColor=new XSSFColor(color,map);
        XSSFFont headerFont = (XSSFFont) wb.createFont();
        color = Color.decode(contentfontcolor);
        xSSFColor=new XSSFColor(color,map);
        //单行样式
        color = Color.decode(contentsinglerowbg); //单行背景色
        xSSFColor=new XSSFColor(color,map);
        if(rowindex%2 == 0){
            //双行样式
            color = Color.decode(contentdoublerowbg); //双行背景色白色
            xSSFColor=new XSSFColor(color,map);
        }
        cellStyle.setFillForegroundColor(xSSFColor);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //内容样式
        XSSFFont contentFont = (XSSFFont) wb.createFont();
        color =Color.decode(contentfontcolor); // 内容列字体颜色
        xSSFColor=new XSSFColor(color,map);
        contentFont.setColor(xSSFColor);
        contentFont.setFontName(contentfont);//内容字体
        contentFont.setFontHeightInPoints(Short.parseShort(contentfontsize));//内容字体大小
        cellStyle.setFont(contentFont);
        cellStyle.setAlignment(contenttextalgin);//内容对齐方式
        color =Color.decode(gridlinecolor); // 边框颜色
        xSSFColor=new XSSFColor(color,map);
        setBorder(cellStyle, xSSFColor, Short.parseShort(gridlinewidth));//设置边框线
        return cellStyle;
    }

    /**
     * 获取对齐方式
     * @return
     */
    private HorizontalAlignment getAlignment(String alignment){
        if ("1".equals(alignment)) {
            return HorizontalAlignment.LEFT;
        }else if ("3".equals(alignment)) {
            return HorizontalAlignment.RIGHT;
        }
        return HorizontalAlignment.CENTER;
    }

    /**
     * 设置边框
     * @param cellStyle
     * @param borderColor
     * @param bordertype 边框样式
     */
    private void setBorder(XSSFCellStyle cellStyle,XSSFColor borderColor,short bordertype){
        BorderStyle borderStyle = BorderStyle.valueOf((short)bordertype);
        cellStyle.setBorderColor(BorderSide.BOTTOM, borderColor);
        cellStyle.setBorderColor(BorderSide.LEFT, borderColor);
        cellStyle.setBorderColor(BorderSide.RIGHT, borderColor);
        cellStyle.setBorderColor(BorderSide.TOP, borderColor);
        cellStyle.setBorderBottom(borderStyle);
        cellStyle.setBorderLeft(borderStyle);
        cellStyle.setBorderRight(borderStyle);
        cellStyle.setBorderTop(borderStyle);
    }

    /**
     * 其它参数的值
     * @param otherPara
     * @param rs
     * @return
     */
    private String getRealOtherPara(String otherPara,Map data) {
        if (otherPara == null) return null;
        String realPara = "";
        ArrayList paraList = Util.TokenizerString(otherPara,"+");
        for (int i=0;i<paraList.size();i++){
            String tempPara = (String)paraList.get(i);
            String tempValue = getRealOtherPara1(tempPara,data);
            String tempValue1=("").equals(tempValue)?" ":tempValue;
            realPara +=tempValue1+"+";
        }
        //去掉最后那个加号
        realPara = realPara.substring(0,realPara.length()-1);
        return realPara;
    }

    /**
     * 获得数据库字段的值
     * @param otherPara1
     * @param rs
     * @return
     */
    private String getRealOtherPara1(String otherPara1,Map data) {
        if (otherPara1 == null) return null;
        String realPara = "";
        int pos = otherPara1.toLowerCase().indexOf("column:");

        if (pos != -1) {
            String tempOtherPara = otherPara1.substring(pos + 7);
            realPara = Util.null2String(data.get(tempOtherPara.toLowerCase()));
        } else {
            realPara = otherPara1;
        }
        return realPara;
    }

    private String getData(User user,String dataSource,String poolname,int pageIndex,int pageSize,String showOrder
            ,boolean iscount){
        RecordSet rs = new RecordSet();
        String sql="";
        String dbtypeStr=rs.getDBType();
        if((poolname.equals("")||poolname.equalsIgnoreCase("null"))){//实际表单
            if (iscount) {//如果是查询记录条数
                sql=spu.getCountSql();
            }else {
                if ("all".equalsIgnoreCase(showOrder)) {
                    sql = spu.getAllPage(false);
                } else {
                    sql = spu.getPageSqlByDBType(pageSize, pageIndex, dbtypeStr);
                }
            }
        }else{//虚拟表单
            dbtypeStr=rs.getDBType(poolname);
            if(dbtypeStr.toLowerCase().indexOf("sqlserver")!=-1){
                dbtypeStr = "sqlserver";
            }else if(dbtypeStr.toLowerCase().indexOf("db2")!=-1){
                dbtypeStr = "db2";
            }else if(dbtypeStr.toLowerCase().indexOf("mysql")!=-1){
                dbtypeStr = "mysql";
            }
            else if(dbtypeStr.toLowerCase().indexOf("postgresql")!=-1){
                dbtypeStr = "postgresql";
            }
            else{
                dbtypeStr = "oracle";
            }
            if (iscount) {//如果是查询记录条数
                sql=spu.getCountSql();
            }else {
                if ("all".equalsIgnoreCase(showOrder)) {
                    sql = spu.getAllPage(false);
                } else {
                    sql = spu.getPageSqlByDBType(pageSize, pageIndex, dbtypeStr);
                }
            }
            sql = sql.replace("&lt;","<").replace("&gt;",">");
        }
        return sql;
    }

    /**
     * 将查询的结果集转化为MAP
     * @param cs
     * @return
     * @throws Exception
     */
    private  Map<String,String> ConnStatement2Map(ConnStatement cs) throws Exception{
        Map<String,String> valueMap=new HashMap<String,String>();
        int columns = cs.getColumnCount();
        if(columns==0) return valueMap;
        EncryptUtil encryptUtil = new EncryptUtil();
        for(int i=0;i<columns;i++){
            String fieldValue = cs.getString(i+1);//QC684817
            if (fieldValue.indexOf("cube~cipher~start")>-1) {
                fieldValue = CubeCipherUitl.decrypt(fieldValue);
            }
            String tablename = this.mainTable;
            String columnName = cs.getColumnName(i+1).toLowerCase();
            if(columnName.startsWith("d_")){
                tablename = this.detailtable;
            }
            fieldValue = (String) encryptUtil.decrypt(tablename, columnName, fieldValue,true);
            valueMap.put(columnName, fieldValue);
        }
        return valueMap;
    }

    /**
     * qc451484
     * 获取统计字段的统计值
     * @param countColumns
     * @return
     */
    private Map<String,String> getCountCV(String countColumns){
        Map<String,String> countCV = new HashMap<String,String>();
        RecordSet rs = new RecordSet();
        if(!"".equals(countColumns)){
            rs = spu.getAllRs(true);
            while(rs.next()){
                countCV=CssRenderDeal.recordSet2Map(rs);
            }
        }
        return countCV;
    }

    /**
     * 得到SQLwhere
     *
     * @param customId    查询列表id
     * @param selectValue 选择框的值
     * @param sqlWhere
     * @return 重组后的sqlwhere
     */
    public String getExportSqlWhere(String customId,String selectValue,String sqlWhere){
        String groupSqlWhere = "";
        RecordSet rs = new RecordSet();
        String sql = "select wb.fieldname,wb.viewtype from mode_exportexcelset mes,mode_customdspfield mcf,workflow_billfield wb where wb.id=mcf.fieldid and mes.customid=mcf.customid and mes.isgroupexport=1 and mcf.isgroup=1 and mes.customid=?";
        rs.executeQuery(sql,customId);
        if(rs.next()){
            String fieldname = rs.getString("fieldname");
            String viewtype = rs.getString("viewtype");
            String tablename = "t1";
            if("1".equals(viewtype)){//明细表
                tablename = "d1";
            }
            if(selectValue.equalsIgnoreCase("empty")){//未分组
                if(selectValue.length()>0){
                    groupSqlWhere = "("+tablename+"."+fieldname+"  is null)";
                }else{
                    groupSqlWhere = "";//分组下拉框的值为空
                }
            }else if(selectValue.equals("all")){//全部
                groupSqlWhere = " 1=1 ";
            }else{
                groupSqlWhere = tablename+"."+fieldname+"="+selectValue;
            }
            if(!Util.null2String(sqlWhere).trim().endsWith("and")){
                sqlWhere+=" and ";
            }
        }
        sqlWhere += groupSqlWhere;
        return sqlWhere;
    }

    private Map<String,String> getSheets(String customId,String defaultSheetName,User user){
        Map<String,String> sheets = new LinkedHashMap<>();
        String sql = "select mcf.fieldid,wbf.fieldname,wbf.viewtype from mode_exportexcelset mes,mode_customdspfield mcf,workflow_billfield wbf where mes.customid=mcf.customid and wbf.id=mcf.fieldid and mes.isgroupexport=1 and mcf.isgroup=1 and mes.customid=?";
        RecordSet rs = new RecordSet();
        rs.executeQuery(sql,customId);
        String groupFieldId = "";//分组字段id
        String fieldname = "";//
        if(rs.next()){
            groupFieldId = rs.getString("fieldid");
            fieldname = rs.getString("fieldname");
            String viewtype = rs.getString("viewtype");
            if(viewtype.equals("1")){//明细表
                fieldname = "d1."+fieldname;
            }else{
                fieldname = "t1."+fieldname;
            }
        }
        if("".equals(groupFieldId)||"1".equals(this.isexptrees)||"2".equals(this.isexptrees)) {//没有开启分组导出，或者没有分组字段 当开启分组查询的时候，不支持分组导出
            if(defaultSheetName.indexOf("~`~`7")!=-1){
                defaultSheetName = Util.formatMultiLang(defaultSheetName,user.getLanguage()+"");
            }
            sheets.put("all",defaultSheetName);//全部
        }else{
            //查询是否设置分组顺序
            CubeSearchService cubeSearchService = new CubeSearchService();
            List<TabPane> tabs = cubeSearchService.getSearchGroupTabs(customId,user);
            for(int i=0;i<tabs.size();i++){
                TabPane tab = tabs.get(i);
                String sheetName = tab.getTitle();
                if(sheetName.indexOf("~`~`7")!=-1){
                    sheetName = Util.formatMultiLang(sheetName,user.getLanguage()+"");
                }
                sheets.put(tab.getKey(),sheetName);
            }
            sql = "select count(1) "+epb.getSqlFrom()+" "+epb.getSqlWhere()+" and "+fieldname+" is null";
            rs.executeQuery(sql);
            if(rs.next()){
                int count = rs.getInt(1);
                if(count<=0){
                    sheets.remove("empty");
                }
            }
        }
        return sheets;
    }


    /**
     * 得到导出字段
     * @param customId
     * @return
     */
    public String getExportFieldsHead(String customId,boolean isCustomExportField){
        String backfields = null;
        if(isCustomExportField){//自定义导出字段
            StringBuffer fields = new StringBuffer();
            fields.append(epb.getPrimaryKey());
            RecordSet recordSet = new RecordSet();//得到所有的字段
            String sql = "select wbf.fieldname,wbf.viewtype from mode_exportexcelfield me,workflow_billfield wbf where me.fieldid=wbf.id and me.customid="+customId;
            recordSet.execute(sql);
            while(recordSet.next()){
                String fieldname = recordSet.getString("fieldname");
                String viewtype = recordSet.getString("viewtype");
                if("1".equals(viewtype)){//明细表字段
                    fields.append(",d1."+fieldname+" as d_"+fieldname);
                }else{//主表字段
                    if(("t1."+fieldname).equalsIgnoreCase(epb.getPrimaryKey()))continue;
                    fields.append(",t1."+fieldname);
                }
            }
            GetExportSetInfo gesi = new GetExportSetInfo(null,null);
            int customid = Integer.parseInt(customId);
            if(gesi.hasField(customid,"modedatacreatedate")){
                fields.append(",t1.modedatacreatedate");
            }
            if(gesi.hasField(customid,"modedatacreater")){
                fields.append(",t1.modedatacreater");
            }
            if(gesi.isOpenLabel(customid)){
                fields.append(",t1.modelableid");
            }
            if(gesi.hasField(customid,"modedatastatus")){
                fields.append(",t1.modedatastatus");
            }
            if(gesi.hasField(customid,"modedatamodifier")){
                fields.append(",t1.modedatamodifier");
            }
            if(gesi.hasField(customid,"modedatamodifydatetime")){
                fields.append(",t1.modedatamodifydatetime");
            }
            if(gesi.hasField(customid,"seclevel")){
                fields.append(",t1.seclevel");
            }
            if(gesi.hasField(customid,"modesecrettime")){
                fields.append(",t1.modesecrettime");
            }
            backfields = fields.toString();
        }else{
            backfields = epb.getBackFields();
        }
        return backfields;
    }

    /**
     * 得到导出字段
     * @param customId
     * @param user
     * @return
     */
    private Map getExportFieldsHead(String customId,User user,boolean isCustomExportField){
        List<Map<String,String>> list = new ArrayList<Map<String,String>>();
        RecordSet rs = new RecordSet();
        if(!isCustomExportField){//没有开启自定义导出字段开关
            return getHeadParam(customId,user);
        }else{
            //自定义导出字段
            String sql = "select a.*,b.tablename,b.detailkeyfield from mode_customsearch a left join workflow_bill b on a.formid=b.id where a.id=?";
            rs.executeQuery(sql,customId);
            boolean isVirtualForm = false;
            if(rs.next()) {
                String isbill = "1";
                String viewtype = "0";
                String opentype = "0";
                String enabled = "0";
                String istitle = "0";
                String showmethod = "0";
                String ismaplocation = "0";
                String vdatasource = "";
                String vprimarykey = "";
                String detailfieldAlias="d_";
                String formID = Util.null2String(rs.getString("formid"));
                String modeId = "" + Util.getIntValue(rs.getString("modeid"), 0);
                isVirtualForm = VirtualFormHandler.isVirtualForm(formID);    //是否是虚拟表单
                Map<String, Object> vFormInfo = new HashMap<String, Object>();
                if(isVirtualForm){
                    vFormInfo = VirtualFormHandler.getVFormInfo(formID);
                    vdatasource = Util.null2String(vFormInfo.get("vdatasource"));	//虚拟表单数据源
                    vprimarykey = Util.null2String(vFormInfo.get("vprimarykey"));	//虚拟表单主键列名称
                }
                RecordSet rs2 = new RecordSet();
                sql = " select t.id,t.fieldname nameTemp,CASE WHEN "+ CommonConstant.DB_ISNULL_FUN+"(mcdf.shownamelabel,0)=0 THEN t.fieldlabel ELSE mcdf.shownamelabel END AS label,t.fielddbtype dbtype,t.fieldhtmltype httype,t.type,me.exportorder,t.viewtype,t.detailtable  from mode_exportexcelfield me " +
                        " left join mode_CustomDspField mcdf on mcdf.fieldid=me.fieldid and mcdf.customid=me.customid " +
                        " ,(select wb.id,wb.fieldname,wb.fieldlabel,wb.fielddbtype,wb.fieldhtmltype,wb.type,wb.viewtype,wb.detailtable from workflow_billfield wb,mode_customsearch mcs where wb.billid=mcs.formid and mcs.id=?)t  where me.customid=? and t.id=me.fieldid and me.isexport=1 " +
                        " union select me.fieldid as id,'1' as nameTemp,2 as label,'3' as dbtype, '4' as httype,5 as type,me.exportorder,0 as viewtype,'' as detailtable from mode_exportexcelfield me,Mode_CustomSearch mc where me.customid=mc.id  and mc.id=? and me.fieldid<0 and me.isexport=1 " +
                        " order by exportorder,id asc";
                rs2.executeQuery(sql,customId,customId,customId);
                while(rs2.next()){
                    String text = "";
                    String column = "";
                    String otherpara = "";
                    String transmethod = "";
                    String fieldid = Util.null2String(rs2.getString("id"));
                    Map<String,String> map = new HashMap<String,String>();
                    String id = rs2.getString("id");
                    if(id.equals("-1")){
                        String para3="column:modedatacreatetime+"+customId+"+"+showmethod+"+column:"+(isVirtualForm?vprimarykey:"id")+"+"+formID;
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(722,user.getLanguage()));
                        column = "modedatacreatedate";
                        otherpara = para3;
                        transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultCreateTime";
                    }else if(id.equals("-2")){
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(882,user.getLanguage()));
                        column = "modedatacreater";
                        otherpara = "column:modedatacreatertype";
                        transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                    }else if(id.equals("-3")){
                        //text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(81287,user.getLanguage()));
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(32011,user.getLanguage()));// ID
                        column = "id";
                        otherpara = "column:dataid";
                        transmethod = "weaver.formmode.search.FormModeTransMethod.getDataId";
                    }else if(id.equals("-4")){
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(176,user.getLanguage()));
                        column = "modelableid";
                        otherpara = modeId;
                        transmethod = "weaver.formmode.search.FormModeTransMethod.getTabLabel";
                    }else if(id.equals("-5")){
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(385992,user.getLanguage()));
                        column = "modedatastatus";
                        otherpara = user.getLanguage()+"";
                        transmethod = "com.api.cube.util.CubeSearchTransMethodProxy.getModedatastatus";
                    }else if(id.equals("-7")){
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(3002,user.getLanguage()));
                        column = "modedatamodifier";
                        otherpara = "column:modedatacreatertype";
                        transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                    }else if(id.equals("-8")){
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(516915,user.getLanguage()));
                        column = "modedatamodifydatetime";
                        otherpara = "modedatamodifydatetime";
                        //transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                    }else if(id.equals("-9")){
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(526505,user.getLanguage()));
                        column = "seclevel";
                        otherpara = user.getLanguage()+""+"+"+"column:modesecrettime";
                        transmethod = "com.api.cube.util.CubeSearchTransMethodProxy.getSeclevelLable";
                    }else{
                        String name = rs2.getString("nameTemp");
                        String label = rs2.getString("label");
                        String htmltype = rs2.getString("httype");
                        String type = rs2.getString("type");
                        String dbtype=rs2.getString("dbtype");
                        int field_viewtype=rs2.getInt("viewtype");
                        String fieldAlias=name;
                        if(field_viewtype==1){
                            fieldAlias=detailfieldAlias+name;
                        }
                        if(isVirtualForm){
                            if(modeId.equals("0")){
                                modeId = "virtual";
                            }
                        }
                        String para3="column:"+(isVirtualForm?vprimarykey:"id")+"+"+id+"+"+htmltype+"+"+type+"+"+user.getLanguage()+"+"+isbill+"+"+dbtype+"+"+istitle+"+"+modeId+"+"+formID+"+"+viewtype+"+"+ismaplocation+"+"+opentype+"+"+customId+"+fromsearchlist"+"+"+showmethod+"+"+user.getUID()+"+"+enabled;
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label),user.getLanguage());
                        text = Util.toHtmlForSplitPage(label);
                        column = fieldAlias;
                        otherpara = para3;
                        transmethod = "weaver.formmode.search.FormModeTransMethod.getOthers";
                    }
                    map.put("id", fieldid);
                    map.put("text", text);
                    map.put("column", column);
                    map.put("otherpara", otherpara);
                    map.put("transmethod", transmethod);
                    map.put("vdatasource", vdatasource);
                    list.add(map);
                }
            }
            Map map = new HashMap();
            map.put("resultList", list);
            return map;
        }
    }


    /**
     * 得到导出字段
     * @param customId
     * @param user
     * @return
     */
    private Map getExportFieldsHeadByUser(String customId,User user,boolean isCustomExportField) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        CustomSearchComInfo customSearchComInfo = new CustomSearchComInfo();
        String modeId = customSearchComInfo.getModeId(customId);
        int formId = com.api.formmode.page.util.Util.toInt(customSearchComInfo.getFormId(customId), 0);
        String detailTable = customSearchComInfo.getDetailTable(customId);
        RecordSet rs = new RecordSet();
        String sqlQueryFields = "  select dataindex from cloudstore_defcol where PAGEUID='mode_customsearch:" + customId + "' and  display='0' and userid = "+user.getUID()+" order by orders";
        RecordSet rsQueryFields = new RecordSet();
        rsQueryFields.execute(sqlQueryFields);
        String sqlQueryFieldInfo = "";
        boolean isVirtualForm = false;
        isVirtualForm = VirtualFormHandler.isVirtualForm(formId);    //是否是虚拟表单
        Map<String, Object> vFormInfo = new HashMap<String, Object>();
        String vdatasource = "";
        String vprimarykey = "";
        int fieldId=0;
        if (isVirtualForm) {
            vFormInfo = VirtualFormHandler.getVFormInfo(formId);
            vdatasource = Util.null2String(vFormInfo.get("vdatasource"));    //虚拟表单数据源
            vprimarykey = Util.null2String(vFormInfo.get("vprimarykey"));    //虚拟表单主键列名称
        }
        while (rsQueryFields.next()) {
            String isbill = "1";
            String viewtype = "0";
            String opentype = "0";
            String enabled = "0";
            String istitle = "0";
            String showmethod = "0";
            String ismaplocation = "0";
            String detailfieldAlias = "d_";
            boolean isdetail =false;
            Map<String, String> map = new HashMap<String, String>();//用于存储字段信息
            String tempField = rsQueryFields.getString("dataindex");
            if(tempField.toLowerCase().equals("isshowlist")){
                continue;
            }
            if (tempField.toLowerCase().startsWith("d_")) {
                String tempField1 = tempField.substring(2, tempField.length());
                if ("".equals(detailTable)) {
                    sqlQueryFieldInfo = " select t.id,t.fieldname nameTemp,t.fieldlabel AS label,t.fielddbtype dbtype,t.fieldhtmltype httype,t.type,t.detailtable  from WORKFLOW_BILLFIELD t " +
                            "  where t.billid =  " + formId + "  and fieldname = '" + tempField + "'";
                } else {
                    DatabaseUtils databaseUtils =new DatabaseUtils();
                    if(databaseUtils.existsColumn(detailTable,tempField1)){
                        sqlQueryFieldInfo = " select t.id,t.fieldname nameTemp,t.fieldlabel AS label,t.fielddbtype dbtype,t.fieldhtmltype httype,t.type,t.detailtable  from WORKFLOW_BILLFIELD t " +
                                "  where t.detailtable =  '" + detailTable + "'  and fieldname = '" + tempField1 + "'";
                        isdetail = true;
                    }else{
                        sqlQueryFieldInfo =" select t.id,t.fieldname nameTemp,t.fieldlabel AS label,t.fielddbtype dbtype,t.fieldhtmltype httype,t.type,t.detailtable  from WORKFLOW_BILLFIELD t " +
                                "  where t.billid =  " + formId + "  and fieldname = '" + tempField + "'";
                    }

//                    sqlQueryFieldInfo = " select t.id,t.fieldname name,t.fieldlabel AS label,t.fielddbtype dbtype,t.fieldhtmltype httype,t.type,t.detailtable  from WORKFLOW_BILLFIELD t " +
//                            "  where t.detailtable =  '" + detailTable + "'  and fieldname = '" + tempField1 + "'";
//                    RecordSet rsQuery = new RecordSet();
//                    rsQuery.execute(sqlQueryFieldInfo);
//                    if(!rsQuery.next()){
//                        sqlQueryFieldInfo =" select t.id,t.fieldname name,t.fieldlabel AS label,t.fielddbtype dbtype,t.fieldhtmltype httype,t.type,t.detailtable  from WORKFLOW_BILLFIELD t " +
//                                "  where t.billid =  " + formId + "  and fieldname = '" + tempField + "'";
//                    }
                }
            } else if ((tempField.toLowerCase().equals("modedatacreatedate")
                    || tempField.toLowerCase().equals("modedatacreater")
                    || tempField.toLowerCase().equals("id")
                    || tempField.toLowerCase().equals("modelableid")
                    || tempField.toLowerCase().equals("modedatastatus")
                    || tempField.toLowerCase().equals("modedatamodifier")
                    || tempField.toLowerCase().equals("modedatamodifydatetime")
                    || tempField.toLowerCase().equals("seclevel"))
                    && !isVirtualForm) {

                if (tempField.toLowerCase().equals("modedatacreatedate")) {
                    fieldId= -1 ;
                } else if (tempField.toLowerCase().equals("modedatacreater")) {
                    fieldId= -2 ;
                } else if (tempField.toLowerCase().equals("id")) {
                    fieldId = -3 ;
                } else if (tempField.toLowerCase().equals("modelableid")) {
                    fieldId = -4 ;
                } else if (tempField.toLowerCase().equals("modedatastatus")) {
                    fieldId = -5 ;
                } else if (tempField.toLowerCase().equals("modedatamodifier")) {
                    fieldId = -7 ;
                } else if (tempField.toLowerCase().equals("modedatamodifydatetime")) {
                    fieldId =  -8;
                } else if (tempField.toLowerCase().equals("seclevel")) {
                    fieldId = -9 ;
                }
                sqlQueryFieldInfo = "select me.fieldid as id,'1' as nameTemp,2 as label,'3' as dbtype, '4' as httype,5 as type,0 as viewtype,'' as detailtable from mode_CustomDspField me  where me.customid="+customId+" and me.fieldid = "+fieldId;
            } else {
                //查询主表信息
                sqlQueryFieldInfo = " select t.id,t.fieldname nameTemp,t.fieldlabel AS label,t.fielddbtype dbtype,t.fieldhtmltype httype,t.type,t.detailtable  from WORKFLOW_BILLFIELD t " +
                        "  where t.billid =  " + formId + "  and fieldname = '" + tempField + "'";
            }

            RecordSet rsQueryFields2 = new RecordSet();
            rsQueryFields2.execute(sqlQueryFieldInfo);
            if (rsQueryFields2.next()) {
                String text = "";
                String column = "";
                String otherpara = "";
                String transmethod = "";
                String fieldid = Util.null2String(rsQueryFields2.getString("id"));
                String id = rsQueryFields2.getString("id");

                if(id.equals("-1")){
                    String para3="column:modedatacreatetime+"+customId+"+"+showmethod+"+column:"+(isVirtualForm?vprimarykey:"id")+"+"+formId;
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(722,user.getLanguage()));
                    column = "modedatacreatedate";
                    otherpara = para3;
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultCreateTime";
                }else if(id.equals("-2")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(882,user.getLanguage()));
                    column = "modedatacreater";
                    otherpara = "column:modedatacreatertype";
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                }else if(id.equals("-3")){
                    //text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(81287,user.getLanguage()));
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(32011,user.getLanguage()));// ID
                    column = "id";
                    otherpara = "column:dataid";
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getDataId";
                }else if(id.equals("-4")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(176,user.getLanguage()));
                    column = "modelableid";
                    otherpara = modeId;
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getTabLabel";
                }else if(id.equals("-5")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(385992,user.getLanguage()));
                    column = "modedatastatus";
                    otherpara = user.getLanguage()+"";
                    transmethod = "com.api.cube.util.CubeSearchTransMethodProxy.getModedatastatus";
                }else if(id.equals("-7")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(3002,user.getLanguage()));
                    column = "modedatamodifier";
                    otherpara = "column:modedatacreatertype";
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                }else if(id.equals("-8")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(516915,user.getLanguage()));
                    column = "modedatamodifydatetime";
                    otherpara = "modedatamodifydatetime";
                    //transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                }else if(id.equals("-9")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(526505,user.getLanguage()));
                    column = "seclevel";
                    otherpara = user.getLanguage()+""+"+"+"column:modesecrettime";
                    transmethod = "com.api.cube.util.CubeSearchTransMethodProxy.getSeclevelLable";
                }else{
                    String name = rsQueryFields2.getString("nameTemp");
                    String label = rsQueryFields2.getString("label");
                    String htmltype = rsQueryFields2.getString("httype");
                    String type = rsQueryFields2.getString("type");
                    String dbtype= rsQueryFields2.getString("dbtype");
                    //  int field_viewtype=rsQueryFields2.getInt("viewtype");
                    String fieldAlias=name;
                    if(isdetail){
                        fieldAlias=detailfieldAlias+name;
                    }
                    if(isVirtualForm){
                        if(modeId.equals("0")){
                            modeId = "virtual";
                        }
                    }
                    String para3="column:"+(isVirtualForm?vprimarykey:"id")+"+"+id+"+"+htmltype+"+"+type+"+"+user.getLanguage()+"+"+isbill+"+"+dbtype+"+"+istitle+"+"+modeId+"+"+formId+"+"+viewtype+"+"+ismaplocation+"+"+opentype+"+"+customId+"+fromsearchlist"+"+"+showmethod+"+"+user.getUID()+"+"+enabled;
                    label = SystemEnv.getHtmlLabelName(Util.getIntValue(label),user.getLanguage());
                    text = Util.toHtmlForSplitPage(label);
                    column = fieldAlias;
                    otherpara = para3;
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getOthers";
                }
                map.put("id", fieldid);
                map.put("text", text);
                map.put("column", column);
                map.put("otherpara", otherpara);
                map.put("transmethod", transmethod);
                map.put("vdatasource", vdatasource);
            }
            list.add(map);
        }
        Map map2 = new HashMap();
        map2.put("resultList", list);
        return map2;
    }








    private Map getHeadParam(String customid,User user) {
        RecordSet RecordSet = new RecordSet();
        RecordSet rs = new RecordSet();
        String detailfieldAlias="d_";
        String formID = "0";
        String modeid = "0";

        String isbill = "1";
        String viewtype = "0";
        String opentype = "0";
        String enabled = "0";
        List<Map<String,String>> list = new ArrayList<Map<String,String>>();
        rs.execute("select a.*,b.tablename,b.detailkeyfield from mode_customsearch a left join workflow_bill b on a.formid=b.id where a.id="+customid);
        String vdatasource = "";
        String vprimarykey = "";
        boolean isVirtualForm = false;
        if(rs.next()){
            formID=Util.null2String(rs.getString("formid"));
            modeid=""+Util.getIntValue(rs.getString("modeid"),0);
            isVirtualForm = VirtualFormHandler.isVirtualForm(formID);	//是否是虚拟表单
            Map<String, Object> vFormInfo = new HashMap<String, Object>();
            if(isVirtualForm){
                vFormInfo = VirtualFormHandler.getVFormInfo(formID);
                vdatasource = Util.null2String(vFormInfo.get("vdatasource"));	//虚拟表单数据源
                vprimarykey = Util.null2String(vFormInfo.get("vprimarykey"));	//虚拟表单主键列名称
            }

            String sqlwhere = " and Mode_CustomDspField.isshow='1' ";
            String sql = "select isorder,ColWidth,workflow_billfield.id as id,workflow_billfield. fieldlabel AS fieldlabel,workflow_billfield.fieldname as name,Mode_CustomDspField.shownamelabel as label"+
                    ",workflow_billfield.fielddbtype as dbtype ,workflow_billfield.fieldhtmltype as httype, workflow_billfield.type as type"+
                    ",Mode_CustomDspField.showorder,Mode_CustomDspField.istitle,Mode_CustomDspField.isstat,Mode_CustomDspField.showmethod"+
                    ",viewtype,workflow_billfield.detailtable,Mode_CustomDspField.ismaplocation,Mode_CustomDspField.editable" +
                    " from workflow_billfield,Mode_CustomDspField,Mode_CustomSearch "+
                    " where Mode_CustomDspField.customid=Mode_CustomSearch.id and Mode_CustomSearch.id="+customid+
                    "  "+sqlwhere+" and workflow_billfield.billid="+formID+"  and   workflow_billfield.id=Mode_CustomDspField.fieldid" +
                    " union select isorder,ColWidth,Mode_CustomDspField.fieldid as id,2 as fieldlabel,'1' as name,shownamelabel as label,'3' as dbtype, '4' as httype,5 as type "+
                    ",Mode_CustomDspField.showorder,Mode_CustomDspField.istitle,Mode_CustomDspField.isstat,Mode_CustomDspField.showmethod" +
                    ",0 as viewtype,'' as detailtable,Mode_CustomDspField.ismaplocation,Mode_CustomDspField.editable"+
                    " from Mode_CustomDspField ,Mode_CustomSearch"+
                    " where Mode_CustomDspField.customid=Mode_CustomSearch.id and Mode_CustomSearch.id="+customid+
                    "  "+sqlwhere+"  and Mode_CustomDspField.fieldid<0" +
                    " order by showorder,id asc";
            RecordSet.execute(sql);
            RecordSet.beforFirst();

            while (RecordSet.next()) {
                String text = "";
                String column = "";
                String otherpara = "";
                String transmethod = "";
                String fieldid = Util.null2String(RecordSet.getString("id"));
                Map<String,String> map = new HashMap<String,String>();
                if(RecordSet.getString("id").equals("-1")){
                    String showmethod = Util.null2o(RecordSet.getString("showmethod"));
                    String para3="column:modedatacreatetime+"+customid+"+"+showmethod+"+column:"+(isVirtualForm?vprimarykey:"id")+"+"+formID;
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(722,user.getLanguage()));
                    //509829创建时间的解析
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    column = "modedatacreatedate";
                    otherpara = para3;
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultCreateTime";
                }else if(RecordSet.getString("id").equals("-2")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(882,user.getLanguage()));
                    //509829创建人的解析
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    column = "modedatacreater";
                    otherpara = "column:modedatacreatertype";
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                }else if(RecordSet.getString("id").equals("-3")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(81287,user.getLanguage()));
                    //509829数据id的解析
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    if(text.equals(Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(81287,user.getLanguage())))){
                        text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(32011,user.getLanguage()));// ID
                    }
                    column = "id";
                    otherpara = "column:dataid";
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getDataId";
                }else if(RecordSet.getString("id").equals("-4")){
                    String istagsetsql = "select count(*) from  modeinfo t where id="+modeid+" and istagset=1";
                    rs.execute(istagsetsql);
                    int counttag = 0;
                    if(rs.next()){
                        counttag = rs.getInt(1);
                    }
                    if(counttag == 0){
                        continue;
                    }
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(176,user.getLanguage()));
                    //509829标签的解析
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    column = "modelableid";
                    otherpara = modeid;
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getTabLabel";
                }else if(RecordSet.getString("id").equals("-5")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(385992,user.getLanguage()));
                    //509829创建状态的解析
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    column = "modedatastatus";
                    otherpara = user.getLanguage()+"";
                    transmethod = "com.api.cube.util.CubeSearchTransMethodProxy.getModedatastatus";
                }else if(RecordSet.getString("id").equals("-7")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(3002,user.getLanguage()));
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    column = "modedatamodifier";
                    otherpara = "column:modedatacreatertype";
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                }else if(RecordSet.getString("id").equals("-8")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(516915,user.getLanguage()));
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    column = "modedatamodifydatetime";
                    otherpara = "column:modedatamodifydatetime";
                    //transmethod = "weaver.formmode.search.FormModeTransMethod.getSearchResultName";
                }else if(RecordSet.getString("id").equals("-9")){
                    text = Util.toHtmlForSplitPage(SystemEnv.getHtmlLabelName(526505,user.getLanguage()));
                    //509829创建状态的解析
                    String label = RecordSet.getString("label");
                    if(!label.equals("")) {
                        label = SystemEnv.getHtmlLabelName(Util.getIntValue(label), user.getLanguage());
                        String text1 = Util.toHtmlForSplitPage(Util.null2String(label));
                        if (!text.equals(text1)) {
                            text = text1;
                        }
                    }
                    column = "seclevel";
                    //  otherpara = user.getLanguage()+"";

                    otherpara = user.getLanguage()+""+"+"+"column:modesecrettime";
                    transmethod = "com.api.cube.util.CubeSearchTransMethodProxy.getSeclevelLable";
                }else if(RecordSet.getString("id").equals("-6")){//自定义按钮添加的操作列，不需要导出
                    continue;
                }else{
                    String name = RecordSet.getString("name");
                    String label = RecordSet.getString("label");
                    String fieldlabel = RecordSet.getString("fieldlabel");
                    String htmltype = RecordSet.getString("httype");
                    String type = RecordSet.getString("type");
                    String id = RecordSet.getString("id");
                    String dbtype=RecordSet.getString("dbtype");
                    String istitle = RecordSet.getString("istitle");
                    String showmethod = Util.null2o(RecordSet.getString("showmethod"));
                    String ismaplocation = Util.getIntValue(RecordSet.getString("ismaplocation"),0)+"";
                    int field_viewtype=RecordSet.getInt("viewtype");
                    String fieldAlias=name;
                    if(field_viewtype==1){
                        fieldAlias=detailfieldAlias+name;
                    }
                    if(isVirtualForm){
                        if(modeid.equals("0")){
                            modeid = "virtual";
                        }
                    }
                    if ("".equals(label)) {
                        label=fieldlabel;
                    }
                    String para3="column:"+(isVirtualForm?vprimarykey:"id")+"+"+id+"+"+htmltype+"+"+type+"+"+user.getLanguage()+"+"+isbill+"+"+dbtype+"+"+istitle+"+"+modeid+"+"+formID+"+"+viewtype+"+"+ismaplocation+"+"+opentype+"+"+customid+"+fromsearchlist"+"+"+showmethod+"+"+user.getUID()+"+"+enabled;
                    label = SystemEnv.getHtmlLabelName(Util.getIntValue(label),user.getLanguage());
//                    text = Util.toHtmlForSplitPage(Util.null2String(label));
                    text = label;
                    text=Util.toExcelData(text);
                    column = fieldAlias;
                    otherpara = para3;
                    transmethod = "weaver.formmode.search.FormModeTransMethod.getOthers";
                }

                map.put("id", fieldid);
                map.put("text", text);
                map.put("column", column);
                map.put("otherpara", otherpara);
                map.put("transmethod", transmethod);
                map.put("vdatasource", vdatasource);
                list.add(map);
            }
        }
        Map map = new HashMap();
        map.put("resultList", list);
        return map;
    }

    /**
     * 得到导出顺序
     * @param customId
     * @return
     */
    public List<String> getExportOrder(String customId,User user){
        GetExportSetInfo getExportSetInfo = new GetExportSetInfo(null,user);
        List<Map<String,String>> list = getExportSetInfo.getExportFields(Integer.parseInt(customId));
        List<String> result = new ArrayList<>();
        for(int i=0;i<list.size();i++){
            Map<String,String> map = list.get(i);
            String isexport = map.get("isexport");
            if("1".equals(isexport)){
                String fieldId = map.get("fieldid");
                if("-4".equals(fieldId)&&!getExportSetInfo.isOpenLabel(Integer.parseInt(customId))){
                    continue;
                }
                result.add(fieldId);
            }
        }
        return result;
    }

    /**
     * 得到excel列宽
     * @param customId
     * @return
     */
    public Map<String,Integer> getColWidth(String customId){
        Map<String,Integer> colWidth = new HashMap<String,Integer>();
        RecordSet rs = new RecordSet();
        String sql = "select wbf.id,mef.colwidth from mode_exportexcelfield mef,mode_exportexcelset me,workflow_billfield wbf where mef.customid=me.customid and me.isexportfield=1 and mef.isexport=1 and wbf.id=mef.fieldid and mef.customid=? " +
                " union select mef.fieldid,mef.colwidth from mode_exportexcelfield mef,mode_exportexcelset me where  mef.customid=me.customid and me.isexportfield=1 and mef.isexport=1 and mef.customid=? and mef.fieldid in(-1,-2,-3,-4,-5,-7,-8)";
        rs.executeQuery(sql,customId,customId);
        while(rs.next()){
            String fieldname = rs.getString("id");
            int colwidth = Util.getIntValue(rs.getString("colwidth"),defaultWidth);
            colWidth.put(fieldname,colwidth);
        }
        return colWidth;
    }

    /**
     * qc451484
     * 获取统计字段类型，若为千分位则为“1”
     * @param countColumns
     * @param sqlFrom
     * @return
     */
    private Map<String,Integer> getCountColumnsDbType(String countColumns,String sqlFrom){
        Map<String,Integer> countColumnsDbType = new HashMap<String,Integer>();
        String[] fromSql = sqlFrom.split(" ");
        RecordSet rs = new RecordSet();
        //System.out.println(fromSql);
        String tabelname = fromSql[1];
        String tableId = "";
        rs.executeSql("SELECT id FROM workflow_bill WHERE tablename='"+tabelname+"'");
        while (rs.next()){
            tableId = rs.getString("id");
        }
        if("".equals(tableId)){
            rs.executeSql("SELECT formid FROM mode_customsearch WHERE id="+modeCustomid);
            while(rs.next()){
                tableId = rs.getString("formid");
            }
        }
        String[] countColumns1 = countColumns.split(",");
        for(String s : countColumns1){
            String s1= s;
            if(s.startsWith("d_")){ // 以 d_  开头表示是明细表字段
                s =s.substring(2);
            }
            rs.executeSql("SELECT fieldhtmltype,type FROM workflow_billfield WHERE fieldname='"+s+"' AND billid="+tableId);
            while (rs.next()){
                if(rs.getString("fieldhtmltype").equals("1")){
                    if(rs.getString("type").equals("5")){
                        countColumnsDbType.put(s1.toLowerCase(),1);
                    }else{
                        countColumnsDbType.put(s1.toLowerCase(),0);
                    }
                }
            }
        }
        return countColumnsDbType;
    }

    /**
     * qc451484
     * 获取统计字段的小数位数
     * @param countColumns
     * @param sqlFrom
     * @return
     */
    private Map<String,String> getDecimalCV(String countColumns,String sqlFrom){
        Map<String,String> decimalCV = new HashMap<String,String>();
        Boolean isVsql = false;
        String tempFromSql = sqlFrom.toLowerCase().trim();
        if (tempFromSql.startsWith("from")){
            tempFromSql = tempFromSql.split("from")[1].trim();
            if (tempFromSql.startsWith("(")){
                isVsql = true;
            }
        }

        String[] fromSql = sqlFrom.split(" ");
        RecordSet rs = new RecordSet();
        String tabelname = fromSql[1];
        String tableId = "";
        rs.executeQuery("SELECT id FROM workflow_bill WHERE tablename=?",tabelname);
        while (rs.next()){
            tableId = rs.getString("id");
        }
        if("".equals(tableId)){
            rs.executeQuery("SELECT formid FROM mode_customsearch WHERE id=?",modeCustomid);
            while(rs.next()){
                tableId = rs.getString("formid");
            }
        }
        String detailTableName = "";
        if(fromSql.length >= 5 && !isVsql ) detailTableName = fromSql[5];
        String[] countColumns1 = countColumns.split(",");
        for(String s : countColumns1) {
            String qfws = "";
            String sql = "SELECT qfws,fieldhtmltype,type FROM workflow_billfield WHERE fieldname='" + s + "' AND billid=" + tableId;
            rs.execute(sql);
            boolean flag = rs.next();
            if(!flag){
                String fieldname = "";
                if(s.indexOf("d_") > -1){
                    fieldname = s.substring(2,s.length());
                }
                if("".equals(detailTableName)){
                    sql = "SELECT qfws,fieldhtmltype,type FROM workflow_billfield WHERE fieldname='" + fieldname + "' AND billid=" + tableId;
                }else{
                    sql = "SELECT qfws,fieldhtmltype,type FROM workflow_billfield WHERE fieldname='" + fieldname + "' AND billid=" + tableId+" and detailtable = '"+detailTableName+"'";
                }
                rs.execute(sql);
                flag = rs.next();
            }
            if (flag){
                if(rs.getString("fieldhtmltype").equals("1")){
                    if(rs.getString("type").equals("4")){
                        decimalCV.put(s.toLowerCase(),"%.2f");
                    }else{
                        if(rs.getString("qfws") != null && !rs.getString("qfws").equals("")){
                            qfws = "%."+rs.getString("qfws")+"f";
                            decimalCV.put(s.toLowerCase(),qfws);
                        }
                    }
                }
            }
        }
        return decimalCV;
    }

    private void createFile(SXSSFWorkbook wb,String filename){
        String key =Util.null2String(parmMap.get("key"));
        String expFile = FileUtils.getExpCreateDir()+key+File.separator;
        new FormmodeLog().writeLog("生成的文件路径"+expFile);
        OutputStream os = null;
        try{
            if (FileUtils.createDir(expFile)) {
                File file = new File(expFile+filename);
                if(!file.exists()){
                    file.createNewFile();
                }
                os = new FileOutputStream(file);
                wb.write(os);
                wb.close();
                String ip=Util.null2String(parmMap.get("param_ip"));
                ExpCardUtil.insertExpLog(modeCustomid, user.getUID(), ip, 0, maincount, expFile+filename, Util.null2String(parmMap.get("excelName")+".xlsx"));
            }
        }catch(Exception e){
            new FormmodeLog().writeLog(e);
        }finally{
            try {
                if(os!=null)
                    os.close();
                if(wb!=null)
                    wb.close();
            } catch (Exception e) {
                new FormmodeLog().writeLog(e);
            }
        }
    }
    /**
     * 按行写入组合数据
     */
    private void writeTreeRowData(ArrayList allDatas,String countColumns,Map<String,Integer>	countColumnsDbType,SXSSFWorkbook workbook,
                                  SXSSFSheet sheet,boolean flag,String from,String iscustomsearch,String[] countColumnArr,Map<String,String> countCV
            ,Map<String,String> decimalCV){
        String sql = "";
        Map<String,String> qfwsMap0 = new ConcurrentHashMap<String,String>();
        Map<String,String> qfwsMap1 = new ConcurrentHashMap<String,String>();
        Map<String,String> selectMap = new ConcurrentHashMap<String,String>();
        HashMap<String,HashMap<String, String>> browserMap = new HashMap<String, HashMap<String,String>>();
        Map<String,Map<String,String>> barcodeMap=new HashMap<String,Map<String,String>>();
        String timeZone = TimeZoneVar.getTimeZone();
        String starttime = DateHelper.getCurDateTime();
        long begin = new Date().getTime();
        RecordSet RecordSet = new RecordSet();
        RecordSet rs = new RecordSet();
        BrowserComInfo BrowserComInfo  = null;
        ProjectInfoComInfo ProjectInfoComInfo1 = null;
        ResourceComInfo rc  = null;
        CustomerInfoComInfo cci  = null;
        WorkflowRequestComInfo WorkflowRequestComInfo1  = null;
        ResourceConditionManager rcm  = null;
        DocReceiveUnitComInfo duc  = null;
        DocComInfo DocComInfo1  = null;
        ExportFieldTransAction fieldTransAction = null;
        //导出转换接口字段配置
        List<String> transFields = new ArrayList<String>();
        Map<String, Object> transMap = new HashMap<String, Object>();
        FormModeTransMethod formModeTransMethod = new FormModeTransMethod();
        ConnStatement cs=null;
        try {
            BrowserComInfo = new BrowserComInfo();
            ProjectInfoComInfo1 = new ProjectInfoComInfo();
            rc = new ResourceComInfo();
            cci = new CustomerInfoComInfo();
            WorkflowRequestComInfo1 = new WorkflowRequestComInfo();
            rcm = new ResourceConditionManager();
            duc = new DocReceiveUnitComInfo();
            DocComInfo1 = new DocComInfo();
            XSSFCellStyle doubleStyle = allstyle.get("doubleStyle");
            XSSFCellStyle singleStyle = allstyle.get("singleStyle");
            int random =(int) (20+Math.random()*30);
            int multiple=1;
            boolean havedata=false;
            for (int z = 0; z < allDatas.size();z++) {
                havedata=true;
                Map dataMap = (Map)allDatas.get(z);
                if (random==this.rowindexs) {
                    if (StringCacheMap.containsKey(key+"_cancel")) {//如果取消
                        break;
                    }
                    progress.put("current", this.rowindexs);
                    syncProgress();
                    random =(int) (20+Math.random()*30)+random;
                }
                if (this.rowindexs==multiple*10000) {//每1w条数据刷新下当前用户导出状态,防止数据过多超过60s未活动被移除
                    ExpExcelUtil.refreshExpUserStateNew(user.getUID());
                    multiple++;
                }
                Map<String, String> data = dataMap;
                boolean barFlag = true;
                transMap.put("data", data);
                SXSSFRow row = sheet.createRow(this.rowindexs);
                XSSFCellStyle cellStyle = this.rowindexs%2==0?doubleStyle:singleStyle;
                //如果第一列有统计字段,则空一列
                SXSSFCell cell;
                ArrayList subList = (ArrayList)dataMap.get("subList");
                //查询是否开启了条形码功能
                String isUsed = "";
                String codenum = "";
                for (int i = 0; i < columnList.size(); i++) {
                    String tempColumnName = Util.null2String(columnList.get(i)).toLowerCase();
                    if("modedatacreatedate".equals(tempColumnName)){
                        tempColumnName=tempColumnName+"1";
                    }
                    String tempTransfMethod = (String) trasforMethodList.get(i);
                    String otherpara = getRealOtherPara((String) otherparaList.get(i).replace("modedatacreatetime","modedatacreatetime1"),data);
                    String val =  StringHelper.null2String(data.get(tempColumnName));
                    transMap.put("columnname", tempColumnName);
                    transMap.put("value", val);
                    String modeid = "";
                    String billid = "";
                    String formid = "";
                    String customid = "";
                    String fieldid = "";
                    barFlag = true;

                    if("prj_viewprocess".equalsIgnoreCase(from)&&"finish".equalsIgnoreCase(tempColumnName)){//项目任务列表
                        tempTransfMethod="";
                    }
                    String transvalue ="";
                    int numbertype = 0;
                    if (otherpara==null){
                        try {
                            transvalue = Util.useSpecialTreat(tempTransfMethod, Util.null2String(data.get(tempColumnName)));
                        } catch (Exception e) {
                            baseBean.writeLog(e);
                        }
                    } else {
                        String[] tempStr = Util.TokenizerString2(otherpara, "+");
                        otherpara = otherpara+"+isExcelOut";
                        if(tempStr.length<9){//创建人,创建日期,标签等特殊字段
                            try {
                                if ("modedatacreatedate1".equals(tempColumnName)) {
                                    fieldid="-1";
                                }else if ("modedatacreater".equals(tempColumnName)) {
                                    fieldid="-2";
                                }else if ("id".equals(tempColumnName)) {
                                    fieldid="-3";
                                }else if ("modelableid".equals(tempColumnName)) {
                                    fieldid="-4";
                                }else if ("modedatastatus".equals(tempColumnName)) {
                                    fieldid="-5";
                                }else if ("modedatamodifier".equals(tempColumnName)) {
                                    fieldid="-7";
                                }else if ("modedatamodifydatetime".equals(tempColumnName)) {
                                    fieldid="-8";
                                }else if ("seclevel".equals(tempColumnName)) {
                                    fieldid="-9";
                                }
                                if (fieldTransAction!=null&&transFields.contains(fieldid)) {
//									transMap.put("fieldid", fieldid);
//									transvalue=fieldTransAction.getTransValue(transMap, user);
                                }else {
                                    if(!StringHelper.isEmpty(tempTransfMethod)&&"weaver.formmode.search.FormModeTransMethod.getDataId".equals(tempTransfMethod)){
                                        transvalue = Util.null2String(data.get(tempColumnName));
                                    }else{
                                        if("-9".equals(fieldid)){
                                            tempColumnName = "seclevel_value";
                                        }
                                        transvalue = Util.useSpecialTreat(tempTransfMethod, Util.null2String(data.get(tempColumnName)),otherpara);
                                    }
                                    if("-2".equals(fieldid) || "-7".equals(fieldid)){
                                        if(transvalue.indexOf("</a>") > -1){
                                            transvalue = transvalue.substring(transvalue.indexOf(">")+1,transvalue.indexOf("</a>"));
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                baseBean.writeLog(e);
                            }
                        }else{
                            fieldid = Util.null2String(tempStr[1]);
                            if (fieldTransAction!=null&&transFields.contains(fieldid)) {
//								transMap.put("fieldid", fieldid);
//								transvalue=fieldTransAction.getTransValue(transMap, user);
                            }else {
                                String fieldhtmltype = Util.null2String(tempStr[2]);
                                String fieldtype = Util.null2String(tempStr[3]);
                                String dbtype = Util.null2String(tempStr[6]);
                                customid = Util.null2String(tempStr[12]);
                                modeid = Util.null2String(tempStr[8]);
                                billid = Util.null2String(tempStr[0]);
                                formid = Util.null2String(tempStr[9]);

                                if(fieldhtmltype.equals("1")){  // 单行
                                    if(fieldhtmltype.equals("1") && fieldtype.equals("2")){//整数
                                        numbertype = 1;
                                        int tempVal = Util.getIntValue(val,-99999999);
                                        if(tempVal!=-99999999){
                                            transvalue = tempVal+"";
                                        }else{
                                            transvalue = "";
                                        }
                                    }else if(fieldhtmltype.equals("1") && fieldtype.equals("4")){//  金额
                                        numbertype = 2;
                                        if(StringHelper.isEmpty(val)){
                                            transvalue = "";
                                        }else{
                                            Pattern pattern = Pattern.compile("^-?(([1-9]\\d*(\\.\\d{1,})?)|(0(\\.\\d{1,})?))$"); //验证浮点数
                                            Matcher isNum = pattern.matcher(val.trim());
                                            if( isNum.matches() ){//非数字
                                                transvalue = val+"";
                                                transvalue = Util.toDecimalDigits(val,2);
                                            }else{
                                                transvalue = "";
                                            }
                                        }
                                    }else if(fieldtype.equals("3")||fieldtype.equals("5")){//浮点数   金额千分位
                                        numbertype = 2;
                                        int decimaldigits_t=0;
                                        if(fieldtype.equals("3")){
                                            int digitsIndex = dbtype.indexOf(",");
                                            if(digitsIndex > -1){
                                                decimaldigits_t = Util.getIntValue(dbtype.substring(digitsIndex+1, dbtype.length()-1), 2);
                                            }else{
                                                decimaldigits_t = 2;
                                            }
                                        }else if(fieldtype.equals("5") ){
                                            if(!StringHelper.isEmpty(val)){
                                                val = val.replace(",", "");
                                            }
                                            int qfws=0;
                                            if(qfwsMap0.containsKey(fieldid)){
                                                qfws = Util.getIntValue(qfwsMap0.get(fieldid),2);
                                            }else{
                                                rs.executeQuery("select qfws from workflow_formdict where id =? " ,fieldid);
                                                if(rs.next()){
                                                    qfws = Util.getIntValue(rs.getString("qfws"),2);
                                                    qfwsMap0.put(fieldid, qfws+"");
                                                }
                                            }
                                            if(qfws==0){
                                                if(qfwsMap1.containsKey(fieldid)){
                                                    qfws=Util.getIntValue(qfwsMap1.get(fieldid),2);
                                                }else{
                                                    RecordSet   rs1=new RecordSet();
                                                    rs1.executeQuery("select qfws from workflow_billfield where id=?",fieldid);
                                                    if(rs1.next()){
                                                        qfws=Util.getIntValue(rs1.getString("qfws"),2);
                                                        if(qfws == -1){
                                                            qfws = 2;
                                                        }
                                                    }
                                                    qfwsMap1.put(fieldid, qfws+"");
                                                }
                                            }
                                            if(qfws <= 0){
                                                qfws = 2;
                                            }
                                            decimaldigits_t = qfws;
                                        }
                                        transvalue = Util.toDecimalDigits(val,decimaldigits_t);
                                    }else{
                                        transvalue=Util.toHtmlSearch(CubeCipherUitl.decrypt(val));
                                    }
                                }else if(fieldhtmltype.equals("2")){//多行文本框
                                    val = Util.null2String(val);
                                    transvalue = convertTextAreaToExcel(val);
                                }else if(fieldhtmltype.equals("3")){
                                    int userlanguage = 7;
                                    String fieldvalue = val;
                                    // 浏览按钮 (涉及workflow_broswerurl表)
                                    if (fieldtype.equals("2") || fieldtype.equals("19") || fieldtype.equals("402") || fieldtype.equals("403")) {    // 日期和时间
                                        transvalue=fieldvalue;
                                    }else if(fieldtype.equals("290")){  //日期时间
                                        //设置时区信息
                                        TimeZoneVar.setTimeZone(timeZone);
                                        fieldvalue="".equals(Util.null2String(fieldvalue))?"":new DateTransformer().getLocaleDateTime(fieldvalue);
                                        transvalue=fieldvalue;
                                    }else if(!fieldvalue.equals("")) {
                                        String showname = "";                                                   // 值显示的名称
                                        String showid = "";                                                     // 值
                                        ArrayList tempshowidlist=Util.TokenizerString(fieldvalue,",");
                                        if(fieldtype.equals("8") || fieldtype.equals("135")){
                                            //项目，多项目
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                showname += ProjectInfoComInfo1.getProjectInfoname((String)tempshowidlist.get(k))+" ";
                                            }
                                        }else if(fieldtype.equals("1") ||fieldtype.equals("17")){
                                            //人员，多人员
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=rc.getResourcename((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=rc.getResourcename((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("7") || fieldtype.equals("18")){
                                            //客户，多客户
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=cci.getCustomerInfoname((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=cci.getCustomerInfoname((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if("4".equals(fieldtype) || "57".equals(fieldtype) || "167".equals(fieldtype) || "168".equals(fieldtype)){
                                            //部门，多部门
                                            OrganizationShowSetBiz orgShowBiz = new OrganizationShowSetBiz();
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=orgShowBiz.getDepartmentShow("model", (String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=orgShowBiz.getDepartmentShow("model", (String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if ("164".equals(fieldtype) || "194".equals(fieldtype) || "169".equals(fieldtype) || "170".equals(fieldtype)) {
                                            // 分部，多分部
                                            OrganizationShowSetBiz orgShowBiz = new OrganizationShowSetBiz();
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=orgShowBiz.getSubcompanyShow("model", (String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=orgShowBiz.getSubcompanyShow("model", (String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("9") || fieldtype.equals("37")){
                                            //文档，多文档
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=DocComInfo1.getDocname((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=DocComInfo1.getDocname((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("22")){ //报销费用类型
                                            FnaSystemSetComInfo fnaSystemSetComInfo = new FnaSystemSetComInfo();
                                            String separator = Util.null2String(fnaSystemSetComInfo.get_separator()).trim();
                                            int enableDispalyAll = Util.getIntValue(fnaSystemSetComInfo.get_enableDispalyAll());
                                            String fullName  = "";
                                            if(enableDispalyAll == 1){
                                                BudgetfeeTypeComInfo budgetfeeTypeComInfo = new BudgetfeeTypeComInfo();
                                                String [] valueArr = fieldvalue.split(",");
                                                for (String keyid : valueArr) {
                                                    fullName = budgetfeeTypeComInfo.getSubjectFullName(keyid, separator);
                                                    showname +=fullName+",";
                                                }
                                                showname = showname.substring(0,showname.length()-1);
                                            }else{
                                                BrowserComInfo bci = new BrowserComInfo();
                                                String tablenamefylx = bci.getBrowsertablename(fieldtype+""); // 浏览框对应的表,比如人力资源表
                                                String columname = bci.getBrowsercolumname(fieldtype+""); // 浏览框对应的表名称字段
                                                String keycolumname = bci.getBrowserkeycolumname(fieldtype+""); // 浏览框对应的表值字段
                                                String bxsql = "select " + keycolumname + "," + columname + " from " + tablenamefylx + " where " + keycolumname + " in ( " + fieldvalue + ")";
                                                rs.executeSql(bxsql);
                                                while (rs.next()) {
                                                    String tempshowname = Util.null2String(rs.getString(2));
                                                    showname +=tempshowname+",";
                                                }
                                                showname = showname.substring(0,showname.length()-1);
                                            }
                                        }else if(fieldtype.equals("16") || fieldtype.equals("152")|| fieldtype.equals("171")){
                                            //相关请求
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=WorkflowRequestComInfo1.getRequestName((String)tempshowidlist.get(k));
                                                }else{
                                                    showname+=WorkflowRequestComInfo1.getRequestName((String)tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }else if(fieldtype.equals("141")){
                                            //人力资源条件
                                            showname+=rcm.getFormShowName(fieldvalue,userlanguage);
                                        }
                                        //added by alan for td:10814
                                        else if(fieldtype.equals("142")) {
                                            //收发文单位
                                            for(int k=0;k<tempshowidlist.size();k++){
                                                if(tempshowidlist.size()==1 || k==tempshowidlist.size()-1){
                                                    showname+=duc.getReceiveUnitName(""+tempshowidlist.get(k));
                                                }else{
                                                    showname+=duc.getReceiveUnitName(""+tempshowidlist.get(k))+",";
                                                }
                                            }
                                        }
                                        else if(fieldtype.equals("161")){//自定义单选
                                            showname = "";                                   // 新建时候默认值显示的名称
                                            showid =fieldvalue;
                                            if(!StringHelper.isEmpty(showid)){
                                                HashMap<String, String> browsers = browserMap.get(dbtype);
                                                if(browsers == null) {
                                                    browsers = new HashMap<String, String>();
                                                    browserMap.put(dbtype, browsers);
                                                }
                                                if(browsers.containsKey(showid)){
                                                    showname+=browsers.get(showid)+" ";
                                                }else{
                                                    try{
                                                        Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(dbtype);
                                                        List<String> castList = ModeCacheManager.getInstance().getBrowserShowNameById(dbtype, showid,user.getLanguage());
                                                        String name = "";
                                                        if(castList.size()==1){
                                                            name = castList.get(0);
                                                        }else{
                                                            BrowserBean bb=browser.searchById(showid);
                                                            name=Util.null2String(bb.getName());
                                                        }
                                                        browsers.put(showid, name);
                                                        showname+=name+" ";
                                                    }catch(Exception e){
                                                        e.printStackTrace();
                                                    }
                                                }
                                            }
                                        }
                                        else if(fieldtype.equals("162")){//自定义多选
                                            showname = "";                                  // 新建时候默认值显示的名称
                                            showid =fieldvalue;                                     // 新建时候默认值
                                            HashMap<String, String> browsers = browserMap.get(dbtype);
                                            if(browsers == null) {
                                                browsers = new HashMap<String, String>();
                                                browserMap.put(dbtype, browsers);
                                            }
                                            try{
                                                Browser browser = ModeCacheManager.getInstance().getBrowserSetMap(dbtype);
                                                List l=Util.TokenizerString(showid,",");
                                                List<String> castList = ModeCacheManager.getInstance().getBrowserShowNameById(dbtype, showid,user.getLanguage());
                                                for(int j=0;j<l.size();j++){
                                                    String curid=(String)l.get(j);
                                                    String name = "";
                                                    if(castList.size()==l.size()){
                                                        name = castList.get(j);
                                                    }else{
                                                        BrowserBean bb=browser.searchById(curid);
                                                        name=Util.null2String(bb.getName());
                                                    }
                                                    browsers.put(curid, name);
                                                    showname+=name+",";
                                                }
                                                if(!"".equals(showname)){
                                                    showname=showname.substring(0,showname.length()-1);
                                                }
                                            }catch(Exception e){
                                            }
                                        }else if (fieldtype.equals("256")||fieldtype.equals("257")) {//自定义树形单选
                                            CustomTreeUtil customTreeUtil = new CustomTreeUtil();
                                            showid = fieldvalue;
                                            showname+=customTreeUtil.getTreeFieldShowName(fieldvalue,dbtype,"onlyname");
                                        }else if(fieldtype.equals("226")){//sap浏览框
                                            showname=fieldvalue;
                                        }else{
                                            String tablename=BrowserComInfo.getBrowsertablename(fieldtype); //浏览框对应的表,比如人力资源表
                                            String columname=BrowserComInfo.getBrowsercolumname(fieldtype); //浏览框对应的表名称字段
                                            String keycolumname=BrowserComInfo.getBrowserkeycolumname(fieldtype);   //浏览框对应的表值字段
                                            fieldvalue=formModeTransMethod.deleteFirstAndEndchar(fieldvalue,",");
                                            if(fieldvalue.indexOf(",")!=-1){
                                                sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+" in( "+fieldvalue+")";
                                            }else {
                                                sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+"="+fieldvalue;
                                            }
                                            RecordSet.execute(sql);
                                            while(RecordSet.next()){
                                                showname+=Util.toScreen(RecordSet.getString(2),userlanguage)+" ";
                                            }
                                            if(!"".equals(showname)){
                                                showname=showname.substring(0,showname.length()-1);
                                            }
                                        }
                                        transvalue=showname.toString();
                                    }

                                }else if(fieldhtmltype.equals("4")) {                    // check框
                                    transvalue=val;
                                }else if(fieldhtmltype.equals("5")){
                                    String key = fieldid+"_"+val;
                                    if(selectMap.containsKey(key)){
                                        transvalue = selectMap.get(key);
                                    }else{


                                        // 查询选择框的所有可以选择的值
                                        //根据fieldid 判断是否是密级字段如果是调用人力资源那边的工具类返回对应的信息
                                        String sqlQueryIsSeclevel = " select count(1) as count from WORKFLOW_BILLFIELD where id = "+fieldid +" and fieldname='seclevel' ";
                                        RecordSet rsQuerySeclevel = new RecordSet();
                                        boolean queryIsSeclevelFlag = rsQuerySeclevel.executeSql(sqlQueryIsSeclevel);
                                        int seclevelCount = 0;
                                        if(queryIsSeclevelFlag && rsQuerySeclevel.next()){
                                            seclevelCount =Util.getIntValue(rsQuerySeclevel.getString("count"));
                                        }
                                        if(seclevelCount>0){
                                            Map<String, Object> param = new HashMap<>();
                                            param.put("selectMap", selectMap);
                                            param.put("userlanguage", user.getLanguage());
                                            param.put("fieldvalue", val);
                                            AddSeclevelUtil addSeclevelUtil = new AddSeclevelUtil();
                                            transvalue= addSeclevelUtil.getSeclevelOptionForExp(param);
                                        }else {
                                            if (fieldtype.equals("2")||val.indexOf(",")>-1) {  // 复选框
                                                ArrayList tempvalues = Util.TokenizerString(val, ",");
                                                List<String> list = ModeCacheManager.getInstance().getSelectShowNameById(fieldid, val, user.getLanguage());
                                                for (int j = 0; j < tempvalues.size(); j++) {
                                                    String selectvalue = (String) tempvalues.get(j);
                                                    String value = "";
                                                    if (list.size() == tempvalues.size()) {
                                                        value = list.get(j);
                                                    } else {
                                                        rs.execute(" select selectname from workflow_selectitem where fieldid='" + fieldid + "' and selectvalue='" + selectvalue + "'");
                                                        if (rs.next()) {
                                                            value = rs.getString("selectname");
                                                        }
                                                    }
                                                    transvalue += value + ",";
                                                }
                                                if (!"".equals(transvalue)) {
                                                    transvalue = transvalue.substring(0, transvalue.length() - 1);
                                                }
                                                selectMap.put(fieldid + "_" + val, transvalue);
                                            } else {
                                                List<String> list = ModeCacheManager.getInstance().getSelectShowNameById(fieldid, val, user.getLanguage());
                                                if (list.size() > 0) {
                                                    transvalue = list.get(0);
                                                    selectMap.put(fieldid + "_" + val, transvalue);
                                                } else {
                                                    rs.execute(" select selectvalue,selectname from workflow_selectitem where fieldid='" + fieldid + "'");
                                                    while (rs.next()) {
                                                        String selvalue = rs.getString("selectvalue");
                                                        String selname = rs.getString("selectname");
                                                        selectMap.put(fieldid + "_" + selvalue, selname);
                                                        if (val.equals(selvalue)) {
                                                            transvalue = selname;
                                                        }
                                                    }
                                                }

                                            }
                                        }



                                    }
                                } else if(fieldhtmltype.equals("7")){ //特殊字段
                                    RecordSet rs1 = new RecordSet();
                                    rs1.executeQuery("select linkaddress,descriptivetext from workflow_specialfield where fieldid =? and isbill = 1",fieldid);
                                    if("1".equals(fieldtype)){ //自定义链接
                                        while(rs1.next()){
                                            transvalue = Util.null2String(rs1.getString("linkaddress"));
                                        }
                                    } else if("2".equals(fieldtype)){//描述性文字
                                        while(rs1.next()){
                                            transvalue = Util.null2String(rs1.getString("descriptivetext"));
                                        }
                                    }
                                }else{
                                    try {
                                        transvalue = Util.useSpecialTreat(tempTransfMethod, Util.null2String(data.get(tempColumnName)),otherpara);
                                        transvalue = Util.HTMLtoTxt(transvalue);
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        }

                    }

                    //如果查询列表显示的条形码，则导出excle的时候对应的字段也要是条形码格式
                    String tempsql = "";
                    if(barcodeMap.containsKey(modeid)){
                        Map<String,String> m=barcodeMap.get(modeid);
                        isUsed=m.get("isUsed");
                        codenum=m.get("codenum");
                    }else{
                        boolean modeIdIsNum = false;
                        Pattern patternisNum = Pattern.compile("^-?[0-9]+");
                        Matcher isNum = patternisNum.matcher(modeid);
                        if(isNum.matches() ){
                            modeIdIsNum=true;
                        }

                        if("".equals(isUsed) && !modeid.equals("")&&modeIdIsNum){
                            tempsql = "select * from mode_barcode where modeid=?";
                            RecordSet.executeQuery(tempsql,modeid);
                            if(RecordSet.next()){
                                isUsed = RecordSet.getString("isused");
                                codenum = RecordSet.getString("codenum");
                            }
                        }
                        Map<String,String> m=new HashMap<String, String>();
                        m.put("isUsed", isUsed);
                        m.put("codenum", codenum);
                        barcodeMap.put(modeid, m);
                    }
                    if("1".equals(isUsed)){
                        String tempnum = "";
                        if(codenum == null || "".equals(codenum)){
                            tempnum = " ";
                        }else{
                            tempnum = BarcodeHandler.replaceField(user,codenum,modeid,billid,formid);
                        }
                        tempsql = "select * from customfieldshowchange where customid=? and fieldid=?";
                        RecordSet.executeQuery(tempsql,customid,fieldid);
                        if(RecordSet.next()){
                            String fieldShowValue = RecordSet.getString("fieldshowvalue");
                            if("#BARCodeImg#".equals(fieldShowValue)){
                                transvalue = tempnum;
                                barFlag = false;
                                if(flag){
                                    infoindex.add(i+1); //如果第一列为统计字段，则需要将index+1
                                }else{
                                    infoindex.add(i); //添加索引
                                }
                            }
                        }
                    }


                    try {
                        if("1".equals(iscustomsearch)){
                            StringBuffer sb = new StringBuffer();
                            Pattern pattern = Pattern.compile("<[aA]*[^>]+?>([^<]*)</[aA]>");
                            Matcher matcher = pattern.matcher(transvalue);
                            while(matcher.find()){
                                String s = matcher.group(1);
                                matcher.appendReplacement(sb, s);
                            }
                            matcher.appendTail(sb);
                            transvalue = sb.toString();
                        }else{
                            transvalue = Util.replace(transvalue,"<[^>]+>","",0);
                        }
                        transvalue = Util.replace(transvalue,"&nbsp;"," ",0);
                        transvalue = Util.replace(transvalue,"&nbsp"," ",0);
                        transvalue = transvalue.trim();
                        transvalue = Util.processBody(transvalue, Util.null2String(Util.null2String(user.getLanguage()),"7"));
                    } catch (Exception e) {
                        baseBean.writeLog(e);
                    }
                    cell=row.createCell(flag?(i+1):i);
                    cell.setCellStyle(cellStyle);
                    if(numbertype==1 && barFlag){
                        if(StringHelper.isEmpty(transvalue)){
                            cell.setCellValue("");
                        }else{
                            int tempvalue = Util.getIntValue(transvalue);
                            if(tempvalue!=0){
                                cell.setCellValue(tempvalue);
                            }
                        }
                    }else if(numbertype==2 && barFlag){
                        if(StringHelper.isEmpty(transvalue)){
                            cell.setCellValue("");
                        }else{
                            //float tempvalue = Util.getFloatValue(transvalue) ;
                            //if(tempvalue != 0.0){
                            //cell.setCellValue(tempvalue) ;
                            //}
                            double tempvalue = Util.getDoubleValue(transvalue) ;
                            String[] tempStr = Util.TokenizerString2(otherpara, "+");//浮点数导出时，设置自定义单元格格式
                            String fieldhtmltype = Util.null2String(tempStr[2]);
                            String fieldtype = Util.null2String(tempStr[3]);
                            String dbtype = Util.null2String(tempStr[6]);
                            int digitsIndex = dbtype.indexOf(",");
                            int decimaldigits_t = 0;
                            if(digitsIndex > -1){
                                decimaldigits_t = Util.getIntValue(dbtype.substring(digitsIndex+1, dbtype.length()-1), 2);
                            }else{
                                decimaldigits_t = 2;
                            }
                            if("1".equals(fieldhtmltype) && "5".equals(fieldtype)){//金额千分位从数据库查小数位数
                                RecordSet rs1 = new RecordSet();
                                rs1.executeQuery("select qfws from workflow_billfield where id=?",fieldid);
                                while(rs1.next()){
                                    decimaldigits_t = rs1.getInt("qfws");
                                }
                            }
                            CellStyle floatStyle = this.getFloatStyle(decimaldigits_t, workbook, this.rowindexs);
                            cell.setCellValue(tempvalue) ;
                            cell.setCellStyle(floatStyle);
                        }
                    }else{
                        cell.setCellValue(transvalue);
                    }
                }
                this.rowindexs++;
                this.counts = 0;
                if(subList != null && subList.size() > 0) {
                    writeTreeRowData(subList, countColumns, countColumnsDbType, workbook, sheet, flag, from, iscustomsearch, countColumnArr, countCV, decimalCV);
                }
            }
        } catch (Exception e) {
            baseBean.writeLog(e);
        } finally {
            String endtime = DateHelper.getCurDateTime();
            long endt = new Date().getTime();
            long l = endt - begin;
            baseBean.writeLog("excel列表导出：耗时毫秒数："+l+",时间范围：["+starttime+" -至- "+endtime+" ]");
            if (cs!=null) {

            }
        }
    }

    /**
     * 获取子集下的所有数据个数
     * @param subList
     * @return
     */
    private int getDataCount(ArrayList subList){
        if(subList != null && subList.size()>0) {
            this.counts += subList.size();
            for (int i = 0; i < subList.size(); i++) {
                Map dataMap = (Map) subList.get(i);
                ArrayList subl = (ArrayList) dataMap.get("subList");
                if(subl != null && subl.size()>0){
                    getDataCount(subl);
                }
            }
        }
        return this.counts;
    }

    /**
     * 写入数据后，对数据进行分组。
     * @param allDatas
     * @param sheet
     */
    private void estimateData(ArrayList allDatas,SXSSFSheet sheet){
        try {
            for (int z = 0; z < allDatas.size();z++) {
                Map dataMap = (Map)allDatas.get(z);
                Map<String, String> data = dataMap;
                ArrayList subList = (ArrayList)dataMap.get("subList");
                this.rowindexs++;
                int Datacount = getDataCount(subList);
                this.counts = 0;
                if(subList != null && subList.size() > 0){
                    sheet.groupRow(this.rowindexs,this.rowindexs-1+Datacount);
                    estimateData(subList,sheet);
                }
            }
        } catch (Exception e) {
            baseBean.writeLog(e);
        } finally {
        }
    }
    /**
     * 同步进度条信息(集群同步)
     */
    private void syncProgress(){
        StringCacheMap.put(key, progress.toJSONString());
    }

    /**
     * 将查询的结果集转化为MAP
     * @param rs
     * @return
     */
    public  Map<String,String> recordSet2Map(RecordSet rs){
        Map<String,String> valueMap=new HashMap<String,String>();
        String [] columNames=rs.getColumnName();
        if(columNames==null) return valueMap;
        for(String columName:columNames){
            String tablename = this.mainTable;
            if(columName.startsWith("d_")){
                tablename = this.detailtable;
            }
            valueMap.put(columName.toLowerCase(), rs.getString(tablename,columName));
        }
        return valueMap;
    }

}